2

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

Community
  • 1
  • 1
M_S_SAJJAN
  • 167
  • 3
  • 5
  • 17
  • wat error? which line exactly? – Ashok Raj Oct 08 '12 at 09:23
  • 1
    Does this answer your question? [How do I declare a global variable in VBA?](https://stackoverflow.com/questions/2722146/how-do-i-declare-a-global-variable-in-vba) – TylerH Feb 22 '23 at 22:39

1 Answers1

8

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()
....
Asad Saeeduddin
  • 46,193
  • 6
  • 90
  • 139