The only knowledge I have of vba is from browsing code snippets on the web. I need help with naming a range based on the worksheet name. Below is what I've tried, run from a command button:
Private Sub CommandButton1_Click()
Dim ProjID As String
ProjID = Left(ActiveSheet.Name, 4)
ThisWorkbook.Names.Add Name:=ProjID, RefersTo:="=$B$4:$K$23", Visible:=True
End Sub
This returns a runtime '1004' error: That name is not valid, on the red line. It works if I use an explicit string (e.g. "TestString") in place of ProjID, so I suspect the problem may be with how the Dim statement is used. But again, I'm vba illiterate.
Thanks for any help you can send my way.
Private Sub CommandButton1_Click()
Dim ProjID As String
ProjID = Left(ActiveSheet.Name, 4)
ThisWorkbook.Names.Add Name:=ProjID, RefersTo:="=$B$4:$K$23", Visible:=True
End Sub
This returns a runtime '1004' error: That name is not valid, on the red line. It works if I use an explicit string (e.g. "TestString") in place of ProjID, so I suspect the problem may be with how the Dim statement is used. But again, I'm vba illiterate.
Thanks for any help you can send my way.