creating a named range starting at row 2

tourless

Board Regular
Joined
Feb 8, 2007
Messages
140
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

I have a vlookup that's failing to return anything and I think it's because my named range has a header row. Is there are way to name a range based on row 2 to the last row for columns A & B? Right now I have...
Code:
sheet.names.Add Name:="MyName", RefersToR1C1=:"='sheet'!C1:C2"
.

thanks.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I have a vlookup that's failing to return anything and I think it's because my named range has a header row.
No, that wouldn't cause any issues.

Note that I get syntax error when I try to run your code. Does that line of code run for you without error?
What exactly is the address of the range you are trying to name?
 
Upvote 0
No, that wouldn't cause any issues.

Note that I get syntax error when I try to run your code. Does that line of code run for you without error?
What exactly is the address of the range you are trying to name?

No it didn't but I did it like this and it worked.

Code:
sheet.Range("A2:B" & LastRow(sheet)).Name = "NamedRange"

just to note, I have a LastRow function that takes a targetSheet and optional column. comes in really handy.
 
Upvote 0
OK, sounds like you are all set then. Let us know if there is still any issues.
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,344
Members
448,570
Latest member
rik81h

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