VBA select from top to end of column

opislak

Board Regular
Joined
Feb 28, 2017
Messages
68
Hi all,

I try to select a variable range of cells in a column, in order to sort the data alphabetically.
This code does the job allright:
VBA Code:
ws.Sort.SortFields.Add2 Key:=Range("A3:A999"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal 'Group (A-Z)
However, if the data in the column doesn't reach up to row 999, why select that deep? Is there a possibility to select only rows with data in them. Something like this:
VBA Code:
Range("D3", Selection.End(xlDown)).Style = "Percent"
This works fine, too. Can both lines be somehow combined?

Thanks for responses!!
Patrick.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Just use
VBA Code:
Key:=Range("A3"),
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
May I ask another question?
The same for selecting multiple ranges in a table. This code works fine, but again, why select all the way down?
VBA Code:
Range("A3:D999,E3:P999,Q3:Q999,R3:T999,U3:U999,V3:V999,W3:AH999").Select
Many thanks for your reply. Looking forward to it.
Patrick.
 
Upvote 0
That's got nothing to do with sorting, so needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top