M_S_SAJJAN
M_S_SAJJAN

Reputation: 167

How to use variable of one function in another function in vba?

I am facing one small problem please help me.

sub vari()
dim b as integer
dim c as integer
b=6
c=8
end sub

now i want to use b and c in another function .

sub calculate()
dim a as integer
a = c+b
end sub

I am getting error here

Upvotes: 2

Views: 22856

Answers (1)

Asad Saeeduddin
Asad Saeeduddin

Reputation: 46628

You want to use the proper scope for your variables. If you want for b and c to be accessible to both vari() and calculate() you need to declare them globally, like so:

Public b As Integer
Public c As Integer
sub vari()
....

Upvotes: 8

Related Questions