Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Excel VBA - Variables in Public worksheet to be used in a UserForm?
So in the VBA side bar I have Objects (my four worksheets), Forms (my 7 userforms that I made), and Modules (empty).
I have many, many variables in my worksheet code (which includes buttons, ect).
I need to reference these variables in my userform code but have no clue how.
I asked this question last week but wasn't back in time to add more detail. I think I did better this time. I am fairly new to VBA as I started learning it about three weeks ago.
I believe that both of your examples are different situations.
I am writing code in a UserForm. I want to use a variable that was named in a worksheet code.
here is my snippet of code:
Sheets("Time Cards").Range(DayToCell & EmployeeRow + 1) = Now
DayToCell and EmployeeRow are dependent upon code in the worksheet.
I FIGURED IT OUT!!!! after days and days, A simple solution
Insert - Module
In Module add code
Public Variable_Name as Type
ex.
Public MessageCounter as Integer
Public Variable1 as String
YAYYY
4 Answers
- devilishblueyesLv 71 decade agoFavorite Answer
Yes, you're right. You can insert a module then declare a public variable that any sub in your project can use.
Or depending on how you've written your code, you might want to break your larger macro up into several smaller macros and then piece them together in a main macro. For example Macro1 may delete all the extra rows. Macro2 may sort the data. And Macro3 may filter the data. Instead of writing a big lengthy macro every time and re-writing the same code over and over again. You can break it into chunks and put them together in a main macro. So the main macro would simply look like this:
Sub Main
Call Macro1
Call Macro2
Call Macro3
End Sub
- Mister AnswermanLv 71 decade ago
This site has experts in VBA
If you visit this site, you will need to specify what Operating System
you use (NTFS or Vista or 32-bit) and what version of Excel. Excel 2003 or Excel 2007. They are fussy but will assist you if you include code as well. Be descriptive as much as possible. Don't assume everyone knows your thoughts. Use Code tags to enclose any vba code.
Example -
[CODE]
Sub whatrever()
blah blah blah
end sub
[/CODE]
You will need to create a free account to access their services.
Here are some home pages of projects by a VBA enthusiast -
- Anonymous1 decade ago
if you are in the same form and working with vba then you can define by the following:
Me!Input_Name.Value
or
Form_Name!Input_Name.Value
if you are trying to get a value in another form you have to use:
Form_Name!Input_Name.Value