Hello. I am attempting to use a ComboBox that would autofill an existing Excel Form. Basically, I have it set where a user can select an existing entry by reference number. I am trying to set it up so when this is done the rest of the form autopopulates with the rest of the data associated with that reference number. I have run into some issue, however. The ComboBox allows you to select an existing record, but it is not autofilling the rest of the form. The code I am using is below:
Private Sub cmbsearch_Change()
cmbsearch.RowSource = "'CAP'!B2:B10000"
Dim capname As Integer
Exit Sub
capname = cmbsearch.Value
On Error Resume Next
Me.txtbox1.Value = Application.WorksheetFunction.VLookup(capname, Sheets(“CAP”).Range("A2:Q10000"), 1, 0)
Me.txtbox2.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 3, 0)
Me.txtbox3.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 4, 0)
Me.txtbox4.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 5, 0)
Me.txtbox5.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 6, 0)
Me.txtbox6.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 7, 0)
Me.txtbox7.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 8, 0)
Me.txtbox8.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 9, 0)
Me.txtbox9.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 10, 0)
Me.txtbox10.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 11, 0)
Me.txtbox11.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 12, 0)
Me.txtbox12.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 13, 0)
Me.txtbox13.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 14, 0)
Me.txtbox14.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 15, 0)
Me.txtbox15.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 16, 0)
Me.txtbox16.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 17, 0)
Me.txtbox17.Value = Application.WorksheetFunction.VLookup(capname, Worksheets(“CAP”).Range("A2:Q10000"), 18, 0)
End Sub
Thanks in advance for any help you can provide. Please let me know if you need more information.
Bookmarks