I'm having an issue which appears to be simple, but I can't figure out what's the problem with my code.
Dim x As Long, y As Long, z As Long
Dim ContractName As String
Dim RangeToName As Range
y = Cells(1, 1).End(xlToRight).Column
For x = 1 To y
ContractName = Cells(1, x)
z = Cells(Rows.count, x).End(xlUp).Row
Set RangeToName = Range(Cells(2, x), Cells(z, x))
RangeToName.Name = ContractName
Next x
End Sub
I'm trying to name ranges based on the text in the "ContractName" cell which will change for each x.
But the line "RangeToName.Name = ContractName" gives me a run-time 450 error.
However if I add any other text in that line for example "RangeToName.Name = "test" & ContractName" everything works and my ranges are named with the full string of text including the text in the "ContractName" cell...
What am I missing?
Cheers
ContractName = Cells(1,x).ValueorContractName = Cells(1,x).Text?