ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating range name based on cell value. (https://www.excelbanter.com/excel-programming/433192-creating-range-name-based-cell-value.html)

jeff

Creating range name based on cell value.
 
Sheet named “Summary” contains a range name “TempNumber”.

I need a macro that will, within the current sheet, go to cell A1. It
will look at the range TempNumber and name the range (of cell A1) a
combination of the word “Vehicle” plus the value in TempNumber.

Example: The value in range TempNumber is "Test1".
This macro will cause Cell A1 of whatever the current sheet is to be
named “Vehicle Test1”
This will be used in different sheets, so I need it to do this in
whatever the Current Sheet is.

Thanks
j.o.

Patrick Molloy[_2_]

Creating range name based on cell value.
 
use the INDIRECT() function

Activesheet.Range("A1").Name = "Vehicle" &
worksheets("Summary").Range("TempNumber").Value



"jeff" wrote:

Sheet named €śSummary€ť contains a range name €śTempNumber€ť.

I need a macro that will, within the current sheet, go to cell A1. It
will look at the range TempNumber and name the range (of cell A1) a
combination of the word €śVehicle€ť plus the value in TempNumber.

Example: The value in range TempNumber is "Test1".
This macro will cause Cell A1 of whatever the current sheet is to be
named €śVehicle Test1€ť
This will be used in different sheets, so I need it to do this in
whatever the Current Sheet is.

Thanks
j.o.


Luke M

Creating range name based on cell value.
 
I believe you're looking for something like this:

Sub NameRange()

'Get Named Value
x = Range(ActiveWorkbook.Names("TempNumber"))

'Create Named Range
'Note that you can't have a space in name
ActiveWorkbook.Names.Add Name:="Vehicle" & x, _
RefersToR1C1:="=" & ActiveSheet.Name & "!R1C1"
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"jeff" wrote:

Sheet named €śSummary€ť contains a range name €śTempNumber€ť.

I need a macro that will, within the current sheet, go to cell A1. It
will look at the range TempNumber and name the range (of cell A1) a
combination of the word €śVehicle€ť plus the value in TempNumber.

Example: The value in range TempNumber is "Test1".
This macro will cause Cell A1 of whatever the current sheet is to be
named €śVehicle Test1€ť
This will be used in different sheets, so I need it to do this in
whatever the Current Sheet is.

Thanks
j.o.


jeff

Creating range name based on cell value.
 
On Sep 3, 10:23*am, Luke M wrote:
I believe you're looking for something like this:

Sub NameRange()

'Get Named Value
x = Range(ActiveWorkbook.Names("TempNumber"))

'Create Named Range
'Note that you can't have a space in name
ActiveWorkbook.Names.Add Name:="Vehicle" & x, _
RefersToR1C1:="=" & ActiveSheet.Name & "!R1C1"
End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*



"jeff" wrote:
Sheet named “Summary” contains a range name “TempNumber”.


I need a macro that will, within the current sheet, go to cell A1. It
will look at the range TempNumber and name the range (of cell A1) a
combination of the word “Vehicle” plus the value in TempNumber.


Example: The value in range TempNumber is "Test1".
This macro will cause Cell A1 of whatever the current sheet is to be
named “Vehicle Test1”
This will be used in different sheets, so I need it to do this in
whatever the Current Sheet is.


Thanks
j.o.- Hide quoted text -


- Show quoted text -


Thanks for both solutions.
I'm getting an error when it comes to this part (same error on the
solution from Patrick).

ActiveWorkbook.Names.Add Name:="Vehicle" & x, _
RefersToR1C1:="=" & ActiveSheet.Name & "!R1C1"

I'll play around with this some more, but maybe there's something
obvious somebody can spot in the syntax.
Thanks
j.o.

Norie

Creating range name based on cell value.
 
What error are you getting?

Both Patrick's and Luke's code work fine for me.:)



All times are GMT +1. The time now is 06:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com