Variables

  • Thread starter Thread starter Tim U
  • Start date Start date
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top