I am using Microsoft 2010. I am new to Excel Macro VBA. I am still confused about the differences between Sub, Public, Global, Function, Dim, and Set. No idea when to use which.
Currently, I have a lot of worksheets and cells that I want to give a variable or name to.
This is not the actual code, but just an example of what I am trying to do.
Sub Example()
'Define Worksheets
Set sheet1 = Worksheets("Red")
Set sheet2 = Worksheets("Blue")
'Define Cells
Set var1 = sheet1.Cells(1,1)
Set var2 = sheet2.Cells(2,2)
'A long code of procedures follow using this variables.
End Sub
Now, I have another set of procedures where I want to use those same variables without having to define them again.
For example,
Sub Example2()
sheet1.Cells(3,3) = var1+var2
End Sub
I know I am supposed to use "Public" or something, but I keep getting errors or my code doesn't run. The only way it runs is if I redefine those variables under each new procedure "Sub ____()."
Also, I want to define these variables, such that I also don't need to re-define them under "Private Sub" (whatever that is).
Also, how do I set up this forum, so I am not viewing my message via HTML format?
Thanks a plenty!
Bookmarks