Dim sampleRange as Range
Set sampleRange = Worksheet.Range(Cells(1,1),Cells(1,4)
sampleRange.Name = "Range1"
MsgBox sampleRange.Name
The above code will show the actual address of the range, not the name. Why?
How do I get a named range to return its name?
You can find a named range by using the Go To feature—which navigates to any named range throughout the entire workbook. You can find a named range by going to the Home tab, clicking Find & Select, and then Go To. Or, press Ctrl+G on your keyboard. In the Go to box, double-click the named range you want to find.
To display a named range on another sheet, you just need to use the formula =name (the range name) and press Shift + Ctrl + Enter keys together.
Select the range you want to name, including the row or column labels. Select Formulas > Create from Selection. In the Create Names from Selection dialog box, designate the location that contains the labels by selecting the Top row,Left column, Bottom row, or Right column check box. Select OK.
For a Range, Name isn't a string it's a Name object, that you then take the Name property of to get the string:
MsgBox sampleRange.Name.Name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With