cwilliams96
Board Regular
- Joined
- Jul 27, 2003
- Messages
- 186
Hi
Can anyone please help? Really struggling as a novice on VBA to pass a variable between 2 subs...
The first sub works fine and counts the number of rows in the data and stores in variable i, which is then used in that sub routine.
The second sub that runs from a button click, I need it to use that variable i in a further process on another worksheet. This is where it fails
I have tried Option Explicit, I have tried making the initial sub Public and other things from the internet, before posting here....
This is where I set the variable i in the initial sub
Dim i As Long
'This counts the rows and stores the value in i
i = Range("A" & Rows.Count).End(xlUp).Row
This is the second sub called from a button click, this is where I have tried to pass the variable,
Sub Invoice_Calc(i As Long)
'--------------------------ADDING FORMULAS TO THE INVOICE CALC SHEET---------------------
Sheets("INVOICE CALC").Select
'This is to see if the variable was passed
MsgBox "Number of Rows = " & i, vbInformation, "ROW COUNT"
Range("L6").Formula = Replace("=SUMIFS('Apps Indicative Earnings Report'!$K$11:$K$#,'Apps Indicative Earnings Report'!$G$11:$G$#,'INVOICE CALC'!H6,'Apps Indicative Earnings Report'!$C$11:$C$#,'INVOICE CALC'!J6,'Apps Indicative Earnings Report'!$D$11:$D$#,'INVOICE CALC'!K6)", "#", i)
Can anyone help?
Thanks
Chris
Can anyone please help? Really struggling as a novice on VBA to pass a variable between 2 subs...
The first sub works fine and counts the number of rows in the data and stores in variable i, which is then used in that sub routine.
The second sub that runs from a button click, I need it to use that variable i in a further process on another worksheet. This is where it fails
I have tried Option Explicit, I have tried making the initial sub Public and other things from the internet, before posting here....
This is where I set the variable i in the initial sub
Dim i As Long
'This counts the rows and stores the value in i
i = Range("A" & Rows.Count).End(xlUp).Row
This is the second sub called from a button click, this is where I have tried to pass the variable,
Sub Invoice_Calc(i As Long)
'--------------------------ADDING FORMULAS TO THE INVOICE CALC SHEET---------------------
Sheets("INVOICE CALC").Select
'This is to see if the variable was passed
MsgBox "Number of Rows = " & i, vbInformation, "ROW COUNT"
Range("L6").Formula = Replace("=SUMIFS('Apps Indicative Earnings Report'!$K$11:$K$#,'Apps Indicative Earnings Report'!$G$11:$G$#,'INVOICE CALC'!H6,'Apps Indicative Earnings Report'!$C$11:$C$#,'INVOICE CALC'!J6,'Apps Indicative Earnings Report'!$D$11:$D$#,'INVOICE CALC'!K6)", "#", i)
Can anyone help?
Thanks
Chris