Public variable

vavs

Well-known Member
Joined
Jul 2, 2004
Messages
516
I have 4 variables that are used between the vba that is run on the worksheet and the userform that elicits responses from the user. The four are declared in the general module like this:

Code:
Public KorS As String
Public ActivityID As String
Public varsaveme As String

I am populating the variables at various points in the code:

Code:
ActivityID = Left(Cells(6, 1), 6)
AdDate = Mid(Cells(6, 1), InStr(1, Cells(6, 1), "Begin Date:") + 12, 10)
If InStr(1, Cells(6, 1), "Comp1") > 1 Then
KorS = "Comp1"
Else
KorS = "Comp2"
End If

and

varsaveme = KorS & "_Annotations_" & Format(M, "00") & Format(D, "00") & YY & "_"

I have the public variables declare in the code for the UserForm also. I did this in the same manner as I did it on the Excel worksheet.

Here is my problem. When I run the program, the information that should be displayed is not appearing. I have checked the variable before the userform opens and it appears to be working. Do I need to set the variables in some other way? Do they need to be declared the same in both the general module and the user form. Can I get a variable back from the userform or do I need to just declare it?

I did this project on a Mac and what I am doing works there but not on a windows server. I am working with Excel 2010 on a Windows Server 2008 R2
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Public variables should declared in a module in the General declarations

You do not need to declare them more than once, and not in the userform

The content of the variable should be available in all parts of the application
 
Upvote 0
Charles, I found that it was a little more than the declaration. I was using a global variable varsaveme, and when I changed the name to V1 it worked. It could be that I used that in another Excel macro and for some reason it was conflicted.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top