sparky_n_ames
New Member
- Joined
- May 20, 2010
- Messages
- 15
I am using this string of code below to name a cell by converting variable Cmt1(Long) into a string variable cellname. I cannot get the line of code below to run. It works fine if I assign a string in "" marks to the variable. I need the variable cellname to match the contents of Variable Cmt1, which in theory it does as written. This is all part of a much longer string of code which runs just fine. I am just an entry level VBA user. I understand objects, properties, variables, etc. I just can't quite understand why this won't work. Any help is appreciated. Thanks.
Dim Cmt1 As Long
Dim celln As Range
Dim cellname As String
cellname = CStr(Cmt1)
'cellname = "FixedStringName" <--This works, but not the line above.
ActiveWorkbook.Names.Add Name:=cellname, RefersTo:=ActiveCell
Dim Cmt1 As Long
Dim celln As Range
Dim cellname As String
cellname = CStr(Cmt1)
'cellname = "FixedStringName" <--This works, but not the line above.
ActiveWorkbook.Names.Add Name:=cellname, RefersTo:=ActiveCell
Last edited: