Resizing a Selected Range using VBA

Jeffrey W Smith

New Member
Joined
Nov 7, 2004
Messages
27
I've been working with VBA for awhile, but I've always had a problem changing the size of a selected range.

For instance, if I have a column of numbers starting in Cell C3, but don't know how many rows it uses, then I have to create a range that goes to the last used cell. Just to make it interesting, there may be blank cells within the column.

With the activecell on the first value in the column:

Code:
Range(activecell,activecell.offset(10000,0)).select
Range(Selection,selection.end(xlup)).select

The last statement doesn't work because it resizes the top of the selected range to Cell C1.

Any suggestions?

Jeff
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Jeff,
I'm not sure if this is what you want, but try this and see if it works for you. This gave the last result in that column for me.
Code:
Sub test()

ActiveCell.Offset(10000, 0).Select
Selection.End(xlUp).Select

End Sub

HTH, Slink
 
Upvote 0
how about;
Code:
Range(ActiveCell, ActiveCell.Offset(10000, 0)).Select
Application.SendKeys "^+{UP}"
 
Upvote 0
Oh, you want the whole range not just the last cell. agihcam's code works great for that :)
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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