0
votes

I have designed UserForm1. There I have ComboBox. I want to open in a module the UserForm1, choose something from ComboBox and after clicking OK in UserForm1 the ComboBox should be assigned to the variable in the module and the code should run further.

I defined public UserForm:

Public Sub UserForm_Initialize()

Dim TCol As Long, CCol As Long
Dim wsRoadmap As Worksheet

Set wsRoadmap = Sheets("Roadmap")

TCol = wsRoadmap.Cells(4, Columns.Count).End(xlToLeft).Column

Me.ComboBox1.Clear

'loop from column C to the last used column of 5th row
For CCol = 3 To TCol
    
    If VBA.Trim(wsRoadmap.Cells(4, CCol).Value) <> "" Then
        Me.ComboBox1.AddItem wsRoadmap.Cells(4, CCol).Value
    End If
    
Next CCol

End Sub

I defined public button in userform

Public Sub but2_Click()

CB1 = Me.ComboBox1.Value
Me.Hide

End Sub

I defined public variable in the module

Public CB1 As String

When I call for userform in my module it popped up but code is running further not waiting on my selection in userform...

1
In the userform properties, do you have "ShowModal" set to True? If not, try that.Christofer Weber
Update your post with the code where you show the userform.Brian M Stafford

1 Answers

0
votes

The solution has been provided by Christofer Weber: "In the userform properties, do you have "ShowModal" set to True? If not, try that". Thank you Chris.