(Solved) – VBA globals passed as variable


I have a VBA project that was working. I think the only change was to move a variable from local to global. The String is as a parameter to a sub. I am now getting a ‘ny idea why? “Database” is one of the sheets in the workbook…

It worked before, and I just changed from local to global (Public Const) variable declarations. Hovering over the variables shows sh=”Database” and rng=”C9:AK47″ as expected. Also that sheet and range is found in the active workbook.

— error: The ‘Set’ line below errors out as ‘subscript not in range’
— question: Why? Sorry I’m not more clear, but it was working, and I just changed one thing…

''' globals
Option Explicit
Public Const gshDb As String = "Database"
Public Const grgDb As String = "C9:AK47"
''' call
breakFormulas True, gshDb, grgDb
''' sub
Sub breakFormulas(switch As Boolean, sh As String, rng As String)
Dim shRng As Range
Set shRng = Sheets(sh).Range(rng) ' yellow highlighted error - subscript out of range

Leave a Reply

Your email address will not be published. Required fields are marked *