![]() |
Add Cell name
Hi Guys, I'm trying to give active cell a name but it doesn't work. Please
help me! Sub CellName() Dim myFile, myKlas, myDiv, myName, rc, ref As String myFile = ActiveSheet.Name ' it's "D35" for example myKlas = myFile myDiv = ActiveCell.Value ' it's "South" for example myName = myKlas & myDiv ' the name I want to give the cell Row = ActiveCell.Row Col = ActiveCell.Column rc = "R" & Row & "C" & Col ref = myFile & "!" & rc ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref & " """ End Sub -- If you are old enough, you have your future behind you. |
Add Cell name
Sub CellName()
Dim myFile, myKlas, myDiv, myName, rc, ref As String Dim nRow As Long, Col As Long myFile = ActiveSheet.Name ' it's "D35" for example myKlas = myFile myDiv = ActiveCell.Value ' it's "South" for example myName = myKlas & myDiv ' the name I want to give the cell nRow = ActiveCell.Row Col = ActiveCell.Column rc = "R" & nRow & "C" & Col ref = myFile & "!" & rc ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref End Sub BTW, all of those variables are not of type string, you need to declare each explicitly, like tis Dim myFile As String, myKlas As String, myDiv As String, myName As String, rc As String, ref As String and you should not use Row as a variable name, it is a VBA keyword. -- __________________________________ HTH Bob "KentAE" wrote in message ... Hi Guys, I'm trying to give active cell a name but it doesn't work. Please help me! Sub CellName() Dim myFile, myKlas, myDiv, myName, rc, ref As String myFile = ActiveSheet.Name ' it's "D35" for example myKlas = myFile myDiv = ActiveCell.Value ' it's "South" for example myName = myKlas & myDiv ' the name I want to give the cell Row = ActiveCell.Row Col = ActiveCell.Column rc = "R" & Row & "C" & Col ref = myFile & "!" & rc ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref & " """ End Sub -- If you are old enough, you have your future behind you. |
Add Cell name
Thanks Bob / Kentae
-- If you are old enough, you have your future behind you. "Bob Phillips" skrev: Sub CellName() Dim myFile, myKlas, myDiv, myName, rc, ref As String Dim nRow As Long, Col As Long myFile = ActiveSheet.Name ' it's "D35" for example myKlas = myFile myDiv = ActiveCell.Value ' it's "South" for example myName = myKlas & myDiv ' the name I want to give the cell nRow = ActiveCell.Row Col = ActiveCell.Column rc = "R" & nRow & "C" & Col ref = myFile & "!" & rc ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref End Sub BTW, all of those variables are not of type string, you need to declare each explicitly, like tis Dim myFile As String, myKlas As String, myDiv As String, myName As String, rc As String, ref As String and you should not use Row as a variable name, it is a VBA keyword. -- __________________________________ HTH Bob "KentAE" wrote in message ... Hi Guys, I'm trying to give active cell a name but it doesn't work. Please help me! Sub CellName() Dim myFile, myKlas, myDiv, myName, rc, ref As String myFile = ActiveSheet.Name ' it's "D35" for example myKlas = myFile myDiv = ActiveCell.Value ' it's "South" for example myName = myKlas & myDiv ' the name I want to give the cell Row = ActiveCell.Row Col = ActiveCell.Column rc = "R" & Row & "C" & Col ref = myFile & "!" & rc ActiveWorkbook.Names.Add Name:=myName, RefersTo:="=" & ref & " """ End Sub -- If you are old enough, you have your future behind you. |
All times are GMT +1. The time now is 02:54 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com