Extracting variables from a UserForm for use in ThisWorkbook module

Rode Peters

New Member
Joined
Mar 6, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I'm using this section of code to call the variables lowOut And upOut from a user form, but can't seem to get it to cooperate.

VBA Code:
' ThisWorkbook Module
'this code runs first

sub ProccesData()
~~~some other variable~~~
    Dim lowOut As Double
    Dim upOut As Double
   
    Load ChartRange
   
    ChartRange.Show vbModal

    MsgBox "lowOut: " & lowOut & vbNewLine & "upOut: " & upOut
   
    Unload ChartRange
~~~rest of code~~~
EndSub

'uf code

Private Sub generatePlotButton_Click()

    Dim lowIn As Double
    Dim upIn As Double
    Dim lowU As String
    Dim upU As String
   
   
    lowIn = ChartRange.lowBndTextBox.value
    upIn = ChartRange.upBndTextBox.value
   
    lowU = ChartRange.lowBndComboBox.value
    upU = ChartRange.upBndComboBox.value
   
    If ((Len(Trim(lowU)) <> 0) Or (Len(Trim(lowU)) <> 0)) Then
        MsgBox "Ploting bound value(s) missing, your doing great bud. give it another try"
        GoTo NextStep
    End If
   
    If StrComp(lowU, "MHz", vbTextCompare) = 0 Then
        lowOut = lowIn * 100000
    ElseIf StrComp(lowU, "GHz", vbTextCompare) = 0 Then
        lowOut = lowIn * 1000000
    Else
        MsgBox "unacceptable lower unit entered, good try bud"
        GoTo NextStep
    End If
   
    If StrComp(upU, "MHz", vbTextCompare) = 0 Then
        upOut = upIn * 100000
    ElseIf StrComp(upU, "GHz", vbTextCompare) = 0 Then
        upOut = upIn * 1000000
    Else
        MsgBox "unacceptable upper unit entered, good try bud"
        GoTo NextStep
    End If
   
    If lowOut >= upOut Then
        MsgBox "Lower bound greater than upper bound, try again buddy"
        GoTo NextStep
    Else
        MsgBox "plotting data from " & lowOut & " Hz to " & upOut & " Hz"
        Unload ChartRange
    End If

NextStep:

    ChartRange.Hide

End Sub
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Remove the declaration lines from your first routine:

Code:
    Dim lowOut As Double
    Dim upOut As Double

and add them to a new normal module but as Public declarations:

Code:
    Public lowOut As Double
    Public upOut As Double
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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