I am using the Name Object to create constants that I’m using in calculations on my worksheets. My problem is that I need to use these same constants in Macros, but can’t seem to create an integer – they keep coming through as strings.
A piece of my code looks like this:
Private Sub Workbook_Open()
'intDocRows
ActiveWorkbook.Worksheets("INV").Names.Add Name:="intDocRows", RefersToR1C1 _
:=16
ActiveWorkbook.Worksheets("INV").Names("intDocRows").Comment = ""
End Sub
Then I need to use this value in a calculation, but it keeps coming through as “=16” instead of 16 in both of the instances below.
ThisWorkbook.ActiveSheet.Names("intDocRows").Value
ThisWorkbook.ActiveSheet.Names("intDocRows").RefersTo
All help is appreciated. Thanx.
It works fine if I use it in a cell though… it’s just in the Macro that I’m having issues.
You could use
Evaluate(ThisWorkbook.ActiveSheet.Names("intDocRows").Value)in your macro code which is simpler than your method. Or even justEvaluate(Names("intDocRows").Value)unless you have the same name scoped on more than one of your worksheets.