How to use Header "Text" as Sort Key

B

Bassman62

How can I use the text within a header cell as a sort key?
For example,
ActiveSheet.Range("A1").CurrentRegion _
.Sort Key1:="DATE", Order1:=xlDescending, _
Key2:="LOCATION", Order2:=xlAsending, Header:=xlYes

Thank you.
 
G

Gary Keramidas

this worked for me, if that's what you're asking:

Sub test()
Dim key2 As String
key2 = Range("b1").Value
With Worksheets("Sheet1").Range("A1:b10").CurrentRegion
.Sort Key1:="DATE", Order1:=xlDescending, _
key2:=key2, Order2:=xlAscending, Header:=xlYes
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top