Using variables in Range

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
367
Office Version
  1. 2019
I have written (cobbled together is probably more accurate) many macros over the last 20 years. I'm by no means proficient, and the simple things still get me confused. One of those is the syntax for defining ranges.
From my current point of view, there seems to be no consistency to it all:
When to use Range
When to use Cells
When to use ,
When to use :
When to use &
When to use column then row
When to use row then column
Where the " quotation marks go

An example: Something like Range("A1:M" & LastRow) works, as does Range("A1", "M" & LastRow), but Range("A1":LastCol&LastRow) does not; niether does Range("A1", LastCol & LastRow)

My immediate problem that lead to writing this post is that I need the correct syntax for addressing A1:LastCol and LastRow
I'm familiar with Range("A1", "D" & LastRow), but cannot work out how to get LastCol AND LastRow in there.

I have searched in vain to find a simple explanation but have come up empty. Can someone point me to something I can bookmark, so I don't have to ask such simple questions on this forum?
 
Every open workbook has an active sheet, so it should really be qualified.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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