OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 439
- Office Version
- 2019
- Platform
- Windows
Hello and thanks in advance for your help and I will provide feedback.
Cells A4 through A28 have the name I would like to use as NameRanges for cells in Cells C4 through C28.
"I am getting a run-time error '1004': The name that you entered is not valid." on the following line:
Entire Code:
Also same error on the following code:
Cells A4 through A28 have the name I would like to use as NameRanges for cells in Cells C4 through C28.
"I am getting a run-time error '1004': The name that you entered is not valid." on the following line:
Code:
Worksheets("1").Names.Add Name:=RangeNameString1, RefersTo:=NameRange1
Entire Code:
Code:
Sub RangeNameOneCell()
Dim i As Integer
Dim RangeNameString1 As String
Dim NameRange1 As Range
Worksheets("1").Activate
For i = 4 To 28
If ActiveSheet.Cells(i, 1).Value <> "" Then
RangeNameString1 = ActiveSheet.Cells(i, 1).Value
Set NameRange1 = ActiveSheet.Range("C" & i)
Worksheets("1").Names.Add Name:=RangeNameString1, RefersTo:=NameRange1
End If
Next i
End Sub
Also same error on the following code:
Code:
Sub RangeName2()
Dim i As Integer
Dim RangeNameString1 As String
Dim RangeNameString2 As String
Dim NameRange1 As Range
Worksheets("1").Activate
For i = 35 To 41
If ActiveSheet.Cells(i, 4).Value <> "" Then
RangeNameString1 = ActiveSheet.Cells(i, 4).Value
Set NameRange1 = ActiveSheet.Range(Cells(i, 7), Cells(i, 1207))
Worksheets("1").Names.Add Name:=RangeNameString1, RefersTo:=NameRange1
End If
Next i
End Sub