ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Variables (https://www.excelbanter.com/excel-programming/302186-variables.html)

Tim U[_2_]

Variables
 
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


Alan Beban[_2_]

Variables
 
Tim U wrote:

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

DavidC[_2_]

Variables
 
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
-----Original Message-----
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

.



All times are GMT +1. The time now is 05:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com