VBA select from top to end of column

opislak

New Member
Joined
Feb 28, 2017
Messages
45
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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,729
Office Version
  1. 365
Platform
  1. Windows
Just use
VBA Code:
Key:=Range("A3"),
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,729
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

opislak

New Member
Joined
Feb 28, 2017
Messages
45
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,729
Office Version
  1. 365
Platform
  1. Windows
That's got nothing to do with sorting, so needs a new thread. Thanks
 

Watch MrExcel Video

Forum statistics

Threads
1,129,931
Messages
5,639,064
Members
417,067
Latest member
rohitbabshet

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
Top