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

Shodi

Board Regular
Joined
May 24, 2016
Messages
50
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.
 

Some videos you may like

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
47,887
Office Version
  1. 365
Platform
  1. Windows
Delete the declaration from the Userform module & put it at the very top of a standard module.
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
47,887
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,111,703
Messages
5,541,303
Members
410,545
Latest member
Upsindustrial20
Top