I am trying to create a macro that will add a value to an existing named range, sort the name alphabetically and then expand the named range to include the new value.
I have managed to get the data into the list, and sort the list alphabetically. The only part I am struggling with is expanding the named range. Can anybody help?
Here is the code so far:
Sub addfault()
'
' addfault Macro
'
'copy new fault
Sheets("Input").Select
Range("F5").Select
Application.CutCopyMode = False
Selection.Copy
'find column
Sheets("Data").Select
Cells.Find(What:=Sheets("Input").Range("D5").Value, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'move selection to bottom of column
ActiveCell.End(xlDown).Offset(1, 0).Select
'paste data
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'move selection to top of column
ActiveCell.End(xlUp).Offset(1, 0).Select
'select column
Range(Selection, Selection.End(xlDown)).Select
'sort a to z
Dim oneRange As Range
Dim aCell As Range
Set oneRange = Selection
Set aCell = ActiveCell
oneRange.Sort Key1:=aCell, Order1:=xlAscending, Header:=xlGuess
End Sub
Bookmarks