Hi,
I have a number or different types of equipment as vehicles on an excel page. Ie Toyota 1993 spans columns A to E in row 1 and Honda 1995 spans columns F to J and so on. Under each vehicle in row 2 there are 5 sub headings: Date, location, comment, ect. New data is entered into this speadsheet by user input in a form. The form seaches for the vehicle in the A row and once it finds it, it goes to the bottom of the sheet and adds the information. Now I want each vehicle in the sheet to be sorted by the date from newest to oldest. Basically I want to select from A3 to E1048576 and sort this data by date (This would be all the information under Toyota), and then I want the macro to automatically offset itself by 5 columns so that it is now at F3 and to select from here to J1048576 (This would be all the information under the Honda) I recorded a macro to sort just one of these areas but I want it to be a variable cell range. Not quite sure how to do this. I've included my code below:
Sheets("Archive").Select
Dim i As Double, value As Double, ws As Worksheet, CellRange As Range
Set ws = Worksheets("Archive")
i = 0
Do
Range("A3").Select
value = i * 5
ActiveCell.offset(0, value).Select
Set CellRange = ws.Range(Range(A3, A1048576), Range(E3, E1048576))
Set CellRange = ws.Range(ActiveCell.Address, ActiveCell.offset(1048576, 4).Address)
With ActiveWorkbook.Worksheets("Archive").Sort
.SetRange Range("CellRange")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Worksheets("Archive").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Archive").Sort.SortFields.Add Key:=Range("CellRange") _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Archive").Sort
.SetRange Range("CellRange")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
i = i + 1
Loop Until i > NumberOfVehicles 'Number of vehicles was previously defined
Bookmarks