mmetzinger
Board Regular
- Joined
- Dec 30, 2010
- Messages
- 61
Ok, so here is a fun one. My boss gave me the task of writing a macro that needs to be completely dynamic. The problem I have run into is when I want to sort the data on a sheet I need the sort procedure to be able to sort based of stored values instead of like "B2","B20".
What I have right now is:
The variables have the following stored values:
FirstCellSort = "4,2"
LastCellSort = "4,20"
This does not work I believe because I am not using a reference like "D2" but instead referencing it as "4,2"
Can anyone help me out?!
What I have right now is:
Code:
Dim FirstCellSort As String
FirstCellSort = CallTypeColumn & ",2"
Dim LastCellSort As String
LastCellSort = CallTypeColumn & "," & LastCell
ActiveWorkbook.Worksheets("Raw Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Raw Data").Sort.SortFields.Add Key:=Range(FirstCellSort, LastCellSort _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
........
FirstCellSort = "4,2"
LastCellSort = "4,20"
This does not work I believe because I am not using a reference like "D2" but instead referencing it as "4,2"
Can anyone help me out?!
Last edited: