Set Range using column and row numbers in VBA - not working

JAzzyD

New Member
Joined
Aug 31, 2016
Messages
5
I have VBA code that sets the range as
Set SCHOOLYRRANGE = .Range("L:L")

and this works fine...

I would like to set SCHOOLYRRANGE using column and row numbers
I tried
Set SCHOOLYRRANGE = .Range(Cells(12, 4), Cells(12, 77333))

77333 is the last row
4 is row where data starts, header is in L3

Thanks. Probably something obvious...
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
Try something like this:-
NB:- Notice Dots in code !!!!
Code:
Dim SCHOOLYRRANGE As Range
With Sheets("Sheet1")
    Set SCHOOLYRRANGE = .Range(.Cells(4, 12), .Cells(77333, 12))
End With
MsgBox SCHOOLYRRANGE.Address(external:=True)
 
Upvote 0

JAzzyD

New Member
Joined
Aug 31, 2016
Messages
5
Thank you that works perfectly.
I did solve it by using:
Set SCHOOLYRRANGE = .Range(Cells(4, 12).Address & ":" & Cells(77333, 12).Address)
but your code is much better and concise...

Thanks again
 
Upvote 0

Forum statistics

Threads
1,191,687
Messages
5,988,014
Members
440,125
Latest member
vincentchu2369

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