I'm Ignorant - When Can I Use a Variant and When Must I name a Range?

Shiseiji

Board Regular
Joined
Oct 23, 2009
Messages
214
Office Version
  1. 2019
Platform
  1. Windows
No formal schooling, 95% of what I know is from the kind people at Mr. Excel. So this may be someone one should learn in Excel 101, but I've missed it.

Why does this work:
Dim LastRow As Long
Dim LastCol As Integer
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column

But this does not work?
Dim rng_HeaderRow As Range
rng_HeaderRow = Range("A1", Cells(LastCol))

Range("A1", Cells(LastCol)).Name = "rng_HeaderRow"
Works but then I have to delete the name or make the named range a worksheet range
TIA

Ron
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You need to use Set when assigning an object variable.
Set rng_HeaderRow =
...
 
Upvote 0
Solution
Thank you. Begs the question why it isn't necessary to:
Set LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row

Ron
 
Upvote 0
Because LastRow is a number (Long integer), not an object.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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