PDA

View Full Version : VBA Macro Sort Range



wskultety
12-29-2022, 04:12 AM
Hi All,
I have to think this is a layup for experts. I have a Range that I want to sort based on the active column.

Range("A2:AZ251").Sort Key1:=Cells(1,ActiveCell.Column) _
Order1:=xlAscending, _
Header:=xlYes

Not working :(

Thanks for your help,
Will

JKwan
12-29-2022, 06:56 AM
try this:

Range("A2:AZ251").Sort Key1:=Cells(1, ActiveCell.Column), _
Order1:=xlAscending, _
Header:=xlYes

wskultety
12-29-2022, 07:28 AM
Still not the case :(

i do love that the single comma was the change :-D

georgiboy
12-29-2022, 07:46 AM
Is it the top row that is not sorting, try extending the range to include the header:

Range("A1:AZ251").Sort Key1:=Cells(1, ActiveCell.Column), _
Order1:=xlAscending, _
Header:=xlYes

Or if your header is in row 2 then maybe:

Range("A2:AZ251").Sort Key1:=Cells(2, ActiveCell.Column), _
Order1:=xlAscending, _
Header:=xlYes

wskultety
12-29-2022, 09:27 AM
Header is in row 1. Even with the change you proposed, still nothing happens. Worksheet doesnt move in anyway.

Thanks for your help nonetheless. Really hope to crack this as it will make a HUGE difference.

Aussiebear
12-29-2022, 12:31 PM
Can you supply a sample workbook?

JKwan
12-29-2022, 12:53 PM
I don't understand..... My sorts without problem

wskultety
12-30-2022, 04:23 AM
Can you supply a sample workbook?

georgiboy
12-30-2022, 04:32 AM
See attached, select any cell with green background and white writing and click the button on the worksheet.

Aussiebear
12-30-2022, 02:20 PM
Man that worksheet is hard on the eyes.

snb
01-01-2023, 09:37 AM
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Windows(1).Zoom = 120
With Range("A1:AZ250")
.Font.Size = 9
If Not Intersect(.Offset, ActiveCell) Is Nothing Then .Sort .Cells(1, ActiveCell.Column), , , , , , , 1
End With
End Sub