tonywatsonhelp
Well-known Member
- Joined
- Feb 24, 2014
- Messages
- 3,210
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
Hi Everyone
The code below works great,
what it does is when I click on cell AJ101
it sorts my data using AJ as the sort column.
Now I want to be able to do this with all the headers in the range, so when I click AC101 it sort by AC ect using the same rules as I currently use.
So how can I change this so it says If target is within Range AB101:AO101 (instead of (If Target.Address = "$AJ$101" Then))
Then sort
and
SortCol ="selected cell" instead of (SortCol = "AJ") ??
any ideas?
Thanks
Tony
The code below works great,
what it does is when I click on cell AJ101
it sorts my data using AJ as the sort column.
Now I want to be able to do this with all the headers in the range, so when I click AC101 it sort by AC ect using the same rules as I currently use.
So how can I change this so it says If target is within Range AB101:AO101 (instead of (If Target.Address = "$AJ$101" Then))
Then sort
and
SortCol ="selected cell" instead of (SortCol = "AJ") ??
any ideas?
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$AJ$101" Then
Sheets("Dashboard1").Unprotect
SortCol = "AJ"
Lrow = Sheets("Dashboard1").Cells(Rows.Count, "AC").End(xlUp).Row
If Lrow < 102 Then
Lrow = 102
End If
Sheets("Dashboard1").Range("AB101", "AO" & Lrow).Sort Key1:=Range(SortCol & "102", SortCol & Lrow), Header:=xlYes, Order1:=xlDescending
Sheets("Dashboard1").Protect
Exit Sub
End If
Thanks
Tony