Variables

T

Tim U

I'm new to VBA and I'm trying to define a variable in one
subroutine and use it in another subroutine but the
variable is resetting to zero in the second subroutine.
What am I missing? Thank you for any help with this.

Sub DownOne()
RowOffset = 1 'defining the variable
Combine 'Second Subroutine
End Sub
 
A

Alan Beban

Tim said:
I'm new to VBA and I'm trying to define a variable in one
subroutine and use it in another subroutine but the
variable is resetting to zero in the second subroutine.
What am I missing? Thank you for any help with this.

Sub DownOne()
RowOffset = 1 'defining the variable
Combine 'Second Subroutine
End Sub
You might try

Sub Combine(rowOffset)
'whatever
End Sub

Sub DownOne()
RowOffset = 1
Call Combine(RowOffset)
End Sub

Alan Beban
 
D

DavidC

Try declaring the variable as Public, at the very top of
the module. Public makes the variable available to all
modules in all, declaring them as Private makes the
variable only available to all procedures in the same
module. Have a look under Help, Declaring variables. Or
look at Public, Private and static to find which
declaration best suits your needs.

All the best

DavidC
 
Top