Calling a Variable from another Module

Dangerm0use

New Member
Joined
Mar 26, 2014
Messages
6
Hi, I need a little help if possible
I am trying to retrieve a calculated variable from withinanother module, and use globally until the session of excel is closed.
I need to pass a 1 or 0 back
SubProductLookupBVC(ByVal control As IRibbonControl)
Dim Common AsNew cCommon
Dim InputCellAs Range
Dim Product AscProduct
Dim h As Long,hdrs As Variant
Dim SelRange AsRange
Dim Score AsLong
Dim LastRow AsLong
Dim Answer AsString
Dim MyNote AsString

Do something
Call CheckFlag ‘ This is the module I want the valuecalculated within see below
If Flag = 1 Then
Do something
Else
Do something else
End if

End Sub


Public Function CheckFlag(Flag As Integer) As Variant
Dim Flag As Integer
Dim MyNote As String
Dim Answer As String
Flag = 0

'Place yourtext here
MyNote ="Do you want to include headers?"

'DisplayMessageBox
Answer =MsgBox(MyNote, vbQuestion + vbYesNo, "???")

If Answer =vbNo Then
Flag = 0
Else
Flag = 1
End If
End Function

Thank you
 
Last edited:

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
First convert CheckFlag into a sub...

Code:
Public Sub CheckFlag(Flag As Integer)
    Dim MyNote As String
    Dim Answer As Long
    
    Flag = 0
    
    'Place your text here
    MyNote = "Do you want to include headers?"
    
    'Display MessageBox
    Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???")
    
    If Answer = vbNo Then
        Flag = 0
    Else
        Flag = 1
    End If
End Sub

Then in ProductLookupBVC...

Code:
    Dim Flag As Integer    

    Call CheckFlag(Flag)

    If Flag = 1 Then
        'Do something
    Else
        'Do something else
    End If

Hope this helps!

P.S. In future, though, please wrap your code within code tags [ CODE] . . . [/CODE]. It makes it easier to read code.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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