Sort columns in range based on selected row

jessrabbit

New Member
Joined
Feb 26, 2011
Messages
15
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;

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:

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Watch MrExcel Video

Forum statistics

Threads
1,108,998
Messages
5,526,161
Members
409,685
Latest member
Bellybb

This Week's Hot Topics

Top