• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Sort Key as range

patsfan

Member
Is it possible to utilize a sort "Key" range address and identify the range elsewhere? My goal is to highlight the sort "Key2" cell from this sort code.

"Cells.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("F2") _

, Order2:=xlAscending, Header:=xlYes"

I am looking to highlight the "Key2" cell address ([F2]) with something like this..."Range("Key2").Interior.ColorIndex = 16"

Thanks
 
You would need to first define that range to a variable. Something like:

[pre]
Code:
Dim KeyRange as Range
Set KeyRange = Range("F2")
Cells.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=KeyRange _
, Order2:=xlAscending, Header:=xlYe
KeyRange.Interior.ColorIndex = 16
[/pre]
The Key2 within the Sort method is just the name of the argument, so you wouldn't be able to reference to it anywhere else within the code. Hope that makes sense.
 
Back
Top