This is a problem linked to the following original question: Cannot vlookup range after name change in VBA
My code is now successfully naming my ranges except in one case:
'Set range for Variance calculation
StartCell = "$B$5"
FinalColumn = wb.Sheets("Pivot Data 3 - To Use").Cells(5, Columns.Count).End(xlToLeft).Column - 1
FinalRow = wb.Sheets("Pivot Data 3 - To Use").Cells(Rows.Count, "B").End(xlDown).Column
With wb.Names("Variance")
.RefersTo = "='Pivot Data 3 - To Use'!" & StartCell & ":" & FinalRow & FinalColumn
.Visible = True
End With
All VBA is telling me is that there is a run time error. When I step through, the code resolves itself to an answer of:
.RefersTo="='Pivot Data 3 - To Use'!$B$5:$Z$47"
but won't apply it to the named range. The code is identical (I copied and pasted) in form to all of the completed assignations so I'm stumped as to why the code falls over here e.g.
'Set range name for Key analysis
With wb.Names("KeyData")
.RefersTo = "='Pivot Data 3 - To Use'!$A$5" & ":$CM$" & LearnerNumbers + 5
.Visible = True
End With
This code works fine.
Any help in wrangling this is greatly appreciated!
Thanks, Steph