jessrabbit
New Member
- Joined
- Feb 26, 2011
- Messages
- 18
Hello, I'm trying to sort the columns in a range of data based on a selected row. I found this code to start with but haven't the knowledge to modify and would appreciate help from someone in the community please.
Here's the code;
The data to be sorted is C9:H12, the column heading is in row 9 and the row label to use as the value to sort on is in column b.
Any help is greatly appreciated.
Thank you, Jess
Here's the code;
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim KeyRange As Range
Dim ColumnCount As Integer
ColumnCount = Range("DataRange").Columns.Count
Cancel = False
If Target.Row = 1 And Target.Column <= ColumnCount Then
Cancel = True
Set KeyRange = Range(Target.Address)
Range("DataRange").Sort Key1:=KeyRange, Header:=xlYes
End If
End Sub</code>
The data to be sorted is C9:H12, the column heading is in row 9 and the row label to use as the value to sort on is in column b.
Any help is greatly appreciated.
Thank you, Jess
Last edited: