How do you populate & initialize user-form from multiple sheets with this VB code?
Hello, I am new to VBA and found the code below 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.
Basically, 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.
Please advise how to further modify the code below the email to capture what I would like to do.
Cheers,
mbizavin
Hello, I am new to VBA and found the code below 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.
Basically, 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.
Please advise how to further modify the code below the email to capture what I would like to do.
Cheers,
mbizavin
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