Hey All, I've been scouring around the forums and haven't been able to come up with a solid answer to this: I'm trying to sort a section of data by a date column. The section to be sorted depends on where the user is entering information. For example the user would press a button to open a form and specify what month they are entering data for. The script finds that month, adds a new line of data, and then I want it to automatically sort the data for February by date.
here's my code so far thats giving me problems, the Set Top and Set Bottom parts is where it hangs. Is there a better way to do this? (the Sorting part I got by recording a macro and changing the values to the variables i set)
Private Sub cbAdd_Click()
Dim Top
Dim Bottom
ActiveCell.Offset(0, -1).Select
Set Top = Range(ActiveCell) 'selects the top of the current range to be sorted
Set Bottom = Range(ActiveCell.End(xlDown)) 'selects the bottom cell of the range to be sorted
Range(Top, Bottom).Select
ActiveWorkbook.Worksheets("Daily 2011").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Daily 2011").Sort.SortFields.Add Key:=Range(Top) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Daily 2011").Sort
.SetRange Range(Top, Bottom)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
End Sub
Bookmarks