How to use combobox value from UserForm to another macro procedure

PAngane

New Member
Joined
Aug 17, 2015
Messages
27
i have created Macro to data entry in excel sheet. in that all the details update automatically. but for 1 field, we need user input through user form.

UserForm is as below.

Combobox1 - 1. AFRICA
2. MIDDLE-EAST

Commandbutton1 - OK

-------------------------------------

my macro is as below.:-

SUB FER Update()
Dim KPReg As String
If destination.Cells(emptyrow, 3) = "MW" Then
destination.Cells(emptyrow, 10) = "ASIA"
ElseIf destination.Cells(emptyrow, 3) = "SR" Then
destination.Cells(emptyrow, 10) = "AMERICAS"
ElseIf destination.Cells(emptyrow, 3) = "KP" Then
UserForm2.Show
End if
end sub ()



command button click event :-
Private Sub CommandButton1_Click()
Unload Me

End Sub

Pls help to modify code
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi,
not fully tested but try following:

Update to your code in STANDARD Module:

Code:
Sub FERUpdate()
    Dim KPReg As String
    Dim m As Variant
     
    With Destination
        m = Application.Match(.Cells(emptyrow, 3), Array("MW", "SR", "KP"), False)
        If Not IsError(m) Then
            If CInt(m) < 3 Then
                .Cells(emptyrow, 10) = Choose(CInt(m), "ASIA", "AMERICAS")
            Else
                .Cells(emptyrow, 10) = UserForm2.GetCountry
            End If
        End If
    End With
    
End Sub

Place ALL following code in your USERFORM Code Page:

Code:
Private Sub CommandButton1_Click()
    Me.Tag = CStr(Me.ComboBox1.Text)
    Me.Hide
End Sub


Private Sub UserForm_Initialize()
    With Me.ComboBox1
        .RowSource = ""
        .List = Array("AFRICA", "MIDDLE-EAST")
    End With
    Me.CommandButton1.Enabled = True
End Sub


Function GetCountry() As String
    Me.Show
    GetCountry = CStr(Me.Tag)
    Unload Me
End Function


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    If CloseMode = 0 Then Cancel = True: Me.Tag = "": Me.Hide
End Sub

Hope Helpful

Dave
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,496
Members
449,089
Latest member
Raviguru

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