Variable Range Size

dtaylor

Active Member
Joined
Mar 21, 2002
Messages
379
Hello All,

I have file that with each update the needed range will vary in size, number of rows and columns will change.

What I am trying to do is be able to select this range.

so far this is what I have:
Range("a65536").End(xlUp).Offset(1, 0).Select
Range(ActiveCell, ActiveCell.End(xlToRight)).Select

This selects only the last row to the last column. What I need to also select all data that precedes. I have searced this board and tried some variations but to now avail.

If someone can fill in the missing piece or direct me in the right direction I would be very appreciated.

Thanks

Dan
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Here is one I have used:
Sub SET_PRINT_AREA3()
Dim range_name, print_range As String
Range("A65536").Select
Selection.End(xlUp).Select
If ActiveCell.Offset(0, 1) <> "" Then
Selection.End(xlToRight).Select
Else
'probably should error out here...
End If
print_range = ActiveCell.Address
range_name = "$A$1:" & print_range
ActiveSheet.PageSetup.PrintArea = range_name
End Sub
 
Upvote 0
Here is another, but it only works if your data goes all the way up to row1:
Sub Macro1()
Selection.End(xlDown).Select
Range("A65536").Select
Selection.End(xlUp).Select
Selection.End(xlToRight).Select
Range(Selection, Cells(1)).Select
End Sub
 
Upvote 0
thanks zzydhf...
although I did not use your suggestions on this project I know I will incorp later.

What I did do was use the statement

Range(Range("a1"), ActiveCell.SpecialCells(xlCellTypeLastCell)).Select

and this worked great! I am aware that this code will go to the last used cell so I had to add another line that cleaned out the previous data!

thanks for your suggestions! This is an awesome site..my hat goes off to Mr.Excel
 
Upvote 0

Forum statistics

Threads
1,203,236
Messages
6,054,300
Members
444,715
Latest member
GlitchHawk

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