Just to add an alternative to the above, as you're not actually making any changes to the integer value and purely using it as a reference in the sub examples you listed you could always pass it as a parameter to the other sub routines:
Sub Main()
Dim i As Integer
' loop thru sheets and...
Hi Shaikhrulez,
Replacing your formula with =SUMIF(B5:B34,"<"& SUBTOTAL(5,B5:B34),D5:D34) should work. Example attached.
It should provide your opening balance for whatever date selection you make.