range question

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

I want to create a range on the active sheet in a workbook
and tried the following code but keep getting an error.
Here is the code:

ActiveWorkbook.Names.Add Name:="Range", RefersToR1C1:="=!
R2C23:R(vlastrow)C24"

I assume I have some type of syntax error.

Since the lastrow in the range will be changing each time
the macro is run, I wanted to use a variable to designate
the last row. Can I do this?

Any help with this issue would be great. Thanks
 
Try this JT

vlastrow = 20
ActiveWorkbook.Names.Add Name:="Range", RefersToR1C1:="=R2C23:R" & vlastrow & "C24"
 
or

ActiveWorkbook.Range("W2:X" & vlastrow).Name = "Range"



--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top