Hello, I am new to VBA and found this code online and modified it to fit my purpose. However, I have a multipage useform and would like to be able to load data from different source worksheets into the userform. Each page has differently labelled combo/text boxes e.g. Page 1 would borrow data from sheet3 and place it into Ctrl1 and text2 etc, while Page 2 would borrow data from sheet1 and place it into CtrlX1 and textX2.
Code:
Private Sub UserForm_Initialize()
ws = Sheet3.Cells(7, 1).CurrentRegion
For j = 3 To UBound(ws)
If InStr(c01 & ",", "," & ws(j, 1) & ",") = 0 Then c01 = c01 & "," & ws(j, 1)
Next
Ctrl1.List = Split(Mid(c01, 2), ",")
End Sub
Function f_list(x)
For j = 3 To UBound(ws)
For jj = 1 To x
If ws(j, jj) <> Me("Ctrl1").Value Then Exit For
Next
If jj = x + 1 And InStr(c01 & ",", "," & ws(j, jj) & ",") = 0 Then c01 = c01 & "," & ws(j, jj)
Next
f_list = Mid(c01, 2)
End Function
Private Sub Ctrl1_Change()
If Ctrl1.ListIndex = -1 Then Exit Sub
c01 = Ctrl1.Value
For j = 3 To UBound(ws)
If ws(j, 1) = c01 Then Exit For
Next
For jj = 2 To 43
Me("text" & jj).Value = ws(j, jj)
Next
End Sub
I would like to source data from sheets 1, 2, 3 and so on and load it onto comboboxes/text boxes on the multipage userform.
I desperately need your help.
Bookmarks