Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default How to use Header "Text" as Sort Key

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How to use Header "Text" as Sort Key

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

--


Gary

"Bassman62" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default How to use Header "Text" as Sort Key

Thank you.
I see that it works better to use the "With" statement.

Dave

"Gary Keramidas" wrote:

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

--


Gary

"Bassman62" wrote in message
...
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.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing sort ascending or descending when go into "data" "sort"? Jason Excel Discussion (Misc queries) 5 September 17th 08 11:57 PM
How to keep "Header Row" button checked during Sort Joe Excel Discussion (Misc queries) 0 March 17th 08 04:13 PM
Listbox header inside VBA (Array("Head1", "Head2", ...) Alex St-Pierre Excel Programming 2 October 25th 06 09:28 PM
How do I display the "ampersand" in the header as text Mark10101010 Setting up and Configuration of Excel 1 May 15th 06 04:01 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM


All times are GMT +1. The time now is 02:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"