melodramatic
Board Regular
- Joined
- Apr 28, 2003
- Messages
- 187
- Office Version
- 365
- Platform
- Windows
I am running a macro that pulls in a grouping of files, and then before sending it to a chart, make sure that all of the data is in timestamp order.
At the top of the pull-in page, I've created cells that do a count of rows and columns (Cell "A1" is the last data row, Cell "A2" is the last column (in this case, DE). I've done this because, depending on the project, both of those counts vary by quite a bit.
In my macro soft portion, my range is not working. Help!
What am I doing wrong? Please help!
Thanks
At the top of the pull-in page, I've created cells that do a count of rows and columns (Cell "A1" is the last data row, Cell "A2" is the last column (in this case, DE). I've done this because, depending on the project, both of those counts vary by quite a bit.
In my macro soft portion, my range is not working. Help!
Code:
Dim LastRow As String '(I've also tried it as Long, but that made no difference)
Dim LastCol As String
Sheets("All Data").Select
LastRow = Range("A1")
LastCol = Range("A2")
Range("A6").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
ActiveWorkbook.Worksheets("All Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("All Data").Sort.SortFields.Add Key:=Range( _ '(THIS IS THE-HILITED SECTION WITH THE RUN-TIME ERROR)
"B6:B:" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("All Data").Sort.SortFields.Add Key:=Range( _
"C6:C" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("All Data").Sort
.SetRange Range("A6:" & LastCol & LastRow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
What am I doing wrong? Please help!
Thanks