Use a Public declared variable across Userforms in the same workbook/worksheet

Shodi

Board Regular
Joined
May 24, 2016
Messages
53
Hi Everyone

I am declaring the result from a msgbox (triggered from a UserForm - named frmSizesASAdd - command button click) as given below (at the very top of the UserForm Module).

The code is as below -

Public DelOnly As VbMsgBoxResult

Private Sub *********_Click()
End Sub
Private Sub *********_Click()
End Sub
Private Sub cmdfrmSizesASAdd_Click()
Dim r As Long, c As Long
r = ActiveCell.Row
c = ActiveCell.Column

If ActiveCell.Offset(0, 11) <> "" Then
DelOnly = msgbox("Will you be making updates to any of the INGREDIENTS FIELDS for " & vbNewLine _
& Cells(r, 2), vbYesNo + vbQuestion + vbDefaultButton1, "PROCESS FLOW CONFIRMATION")
End If

frmIngrPrices.Show

code _________________
code__________________

End Sub

I am trying to access the above DelOnly variable in the below subroutine that is written in a different UserForm named frmIngrPrices but the DelOnly variable is return "Empty" value.

Private Sub cmdfrmIngrPrices_Click()
Dim NRow_Vcount As Long
NRow_Vcount = Range("BC6", Range("BC6").End(xlDown)).Count - 2
If DelOnly = vbYes then
Call SizePriceExtraction(NRow_Vcount)

Please note that the reason I am capturing the msgbox results in the first UserForm is that after the cmdfrmIngrPrices_Click() event is executed I need the code to come back to frmSizesASAdd and execute another UserForm procedure based on the result captured in DelOnly.

How can I call the DelOnly variable, declared and captured in the primary UserForm (frmSizesASAdd) across 2 other UserForms(frmIngrPrices and frmSizePrices) both secondary UserForms triggered using the same command button in UserForm (frmSizesASAdd)?

Please assist. Thanks.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Delete the declaration from the Userform module & put it at the very top of a standard module.
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,929
Messages
6,175,447
Members
452,642
Latest member
acarrigan

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