mattadams84
Board Regular
- Joined
- Oct 30, 2016
- Messages
- 54
Hi,
I have a sheet where the headers i want to sort start in row 4 and the data is below. The first column with data is column B. Depending on the sheet there are different numbers of columns and a different number of rows. I read that it is possible to sort data by double clicking on the headers using VBA. I have found this example
In this code there is already a named range which i do not have. Ideally i dont want to do this with a named range, unless it is created dynamically with VBA. This code has to be placed in the sheet code.
Is it possible to modify this code to adapt to my sheets? I have attached an example of my workbook. I am looking to sort the FHSelections and SHSelections sheets.
https://www.dropbox.com/s/mlwss7s3ueqx6o7/Filters.xlsm?dl=0
I have a sheet where the headers i want to sort start in row 4 and the data is below. The first column with data is column B. Depending on the sheet there are different numbers of columns and a different number of rows. I read that it is possible to sort data by double clicking on the headers using VBA. I have found this example
Code:
[COLOR=#000000][FONT=inherit]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
[/FONT][/COLOR]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
[COLOR=#000000][FONT=inherit]End Sub[/FONT][/COLOR]
In this code there is already a named range which i do not have. Ideally i dont want to do this with a named range, unless it is created dynamically with VBA. This code has to be placed in the sheet code.
Is it possible to modify this code to adapt to my sheets? I have attached an example of my workbook. I am looking to sort the FHSelections and SHSelections sheets.
https://www.dropbox.com/s/mlwss7s3ueqx6o7/Filters.xlsm?dl=0
Last edited: