Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://stackoverflow.com/a/65946006/5079799

Note: Pub Vars easiest, but not portable to multiple Modules calling same UserForm. Is this UserForm NEVER/ALWAYS going to be used with this one Module? Or does it have other possible uses?

Basically, don't declare variables in UserForm. Declare them in Module and assign then my directly referencing UserForm Values like so:

Private Sub UserForm_Initialize()
Dim i As Long
 lCol = Get_lCol(ActiveSheet)
  For i = 1 To lCol
   ColumnLetter = Col_Letter(i)
   Me.ComboBox1.AddItem ColumnLetter
  Next
End Sub
Private Sub CommandButton1_Click()
 Me.Hide
End Sub

Sub PassVarFromUserForm()
 ColPicker.Show
 Dim ColLetter As String
 ColLetter = ColPicker.ComboBox1.Value
 Unload ColPicker
 Debug.Print ColLetter
End Sub
  • No labels