PDA

View Full Version : VBA sort rows based on 1 of 2 values in a Field



deyken
02-16-2012, 11:57 PM
Hi All the VBA/Excel Experts,

First: HAPPY FRIDAY! :hi:

I have to programmatically sort a range of rows in an Excel Worksheet, where 2 rows function as a single record - for construction Projects. Thus, the top row of these two contains a "Planned" date and the second an "Actual" date. Need to have row sorted on this column, based on the "Actual" dates only, but the data row from the "Planned" column needs to stay with the "Actual" data row, as if it is a single excel row. This is what it looks like.

P A

Now, I have the following code to perfom a data sort in VBA, but it only acts on a single row, so it sorts all the "P" together and then all the "A" rows together. How can I fix this?

Sub SortRange2()
Worksheets("Sheet1").Range("A1").Sort _
Key1:=Worksheets("Sheet1").Columns("A"), _
Header:=xlGuess
End Sub

Bob Phillips
02-17-2012, 03:17 AM
Do you have a header row, i.e. is something like

Date
PDate
ADate

in format