Reputation: 13
I want to sort a range of cells using Excel VBA macro
I have searched many websites but everywhere the examples show how to sort multiple columns with a single key
e.g. this example
In example above I want to sort cells A2 to A8, that's it. For this my code is
Range("A2:A8").Sort
But it is giving Runtime error 1004
What is the correct way to do it?
Upvotes: 1
Views: 9990
Reputation: 196
Try this
sub test()
Sheets("sheet1").Range("A2:A8").sort key1:=Range("A2:A8"), order1:=xlAscending, Header:=xlNo
End sub
Upvotes: 4