VBA to combine column letter and row number?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
407
Office Version
  1. 2007
Platform
  1. Windows
I’m not sure this is possible but what I am looking for VBA code to combine a Column letter and Row number where the row changes. I have a cell with range name (LastPmt) that holds the row number.

As example: The last payment is in cell M392. I want a range to be “M33:M392”. However, the row number changes (occasionally the column changes but for now let’s only address the row). Therefore the range should read something like:

Range("M33:M & LastPmt").Select

Thanks for viewing,
Steve
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Remember the following:

Literal text goes between double-quotes.
Variables must be outside double-quotes.
Join the two together with "&", i.e.
Excel Formula:
Range("M33:M" & LastPmt).Select
 
Upvote 0
Remember the following:

Literal text goes between double-quotes.
Variables must be outside double-quotes.
Join the two together with "&", i.e.
Excel Formula:
Range("M33:M" & LastPmt).Select
Hello Joe,
Thank you for your quick response. I modified my code as recommend. Initially I received a Compile error – variable not defined so I added:

Dim LastPmt As Character

However then I received various Run-time errors (91, 1004). I was not sure what variable type to use. Besides Character, I tried String, Label, and Integer.
Any other suggestions would be appreciated.
Again, thanks for viewing. . .
 
Upvote 0
Since you storing the row number, use a numeric type, i.e.
VBA Code:
Dim LastPmt As Long
("Long" stands for "Long Integer")

But that is only if "LastPmt" is a variable you are setting in VBA.
If it is the name of named range from your Excel sheet, you reference it differently.
 
Upvote 0
If the value is stored in a range name "LastPmt" on your sheet, then you would access it like this:
VBA Code:
Range("M33:M" & Range("LastPmt").Value).Select
 
Upvote 0
Solution
WOW, that was fast – thank you.
I changed to: Dim LastPmt As Long
However I’m still getting a
Run-time error ‘1004’ – Method ‘Range’ of object ’_Worksheet’ failed.
 
Upvote 0
Please look at my previous 2 posts.
 
Upvote 0
Please look at my previous 2 posts.
Ahhh - thank you one more time Joe. This worked perfectly. Sorry about being so impatient. I posted my response before the others were visible.
Now on to my next concern. . .

Again, much appreciated,
Steve
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0
You are welcome.
Glad I was able to help!
If the value is stored in a range name "LastPmt" on your sheet, then you would access it like this:
VBA Code:
Range("M33:M" & Range("LastPmt").Value).Select
Joe,

I just wanted to thank you one more time. I've used your suggestion here numerous times with a few variations. It works great!
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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