Populate Userform with Data from External Workbook

Sasha28

New Member
Joined
Mar 30, 2012
Messages
15
I have the following code in my combobox1 on a userform. Is it possible to populate the combobox with data from another workbook (on another drive)? I tried putting in the path of the workbook but that doesn't work. Any help is appreciated. Thank you.


Code:
Dim strFind
Dim rSearch As Range 'range to search
Dim c As Variant
 
Private Sub ComboBox1_Change()
Set rSearch = Sheets("Copiers Master").Range("A2:A94")
strFind = Me.ComboBox1.Value
With rSearch
    Set c = .Find(strFind, LookIn:=xlValues, LookAt:= _
            xlWhole, MatchCase:=True)
    If Not c Is Nothing Then 'found it
        DepartmentTextBox.Value = c.Offset(0, 1).Value
        VendorTextBox.Value = c.Offset(0, 2).Value
        ModelTextBox.Value = c.Offset(0, 3).Value
        LocationTextBox.Value = c.Offset(0, 7).Value
        RenewalAmountTextBox.Value = c.Offset(0, 10).Value
        Account1TextBox.Value = c.Offset(0, 11).Value
        Account1PmtsTextBox.Value = c.Offset(0, 12).Value
        Account2TextBox.Value = c.Offset(0, 13).Value
        Account2PmtsTextBox.Value = c.Offset(0, 14).Value
        Account3TextBox.Value = c.Offset(0, 15).Value
        Account3PmtsTextBox.Value = c.Offset(0, 16).Value
        ContactPhoneTextBox.Value = c.Offset(0, 19).Value
        ContactNameTextBox.Value = c.Offset(0, 20).Value
        ContactEmailTextBox.Value = c.Offset(0, 21).Value
        ApproverNameTextBox.Value = c.Offset(0, 22).Value
        ApproverEmailTextBox.Value = c.Offset(0, 23).Value
        CommentsTextBox.Value = c.Offset(0, 9).Value
 
    End If
End With
End Sub
Private Sub DepartmentTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub InstructionLabel_Click()
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub VendorTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub ModelTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub LocationTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub RenewalAmountTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub Account1TextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub Account1PmtsTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub Account2TextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub Account2PmtsTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub Account3TextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub Account3PmtsTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub ContactPhoneTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub ContactNameTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub ContactEmailTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub ApproverNameTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub ApproverEmailTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub CommentsTextBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call Save_Changes
End Sub
Private Sub Save_Changes()
Set rSearch = Sheets("Copiers Master").Range("A2:A94")
strFind = Me.ComboBox1.Value
With rSearch
    Set c = .Find(strFind, LookIn:=xlValues, LookAt:= _
            xlWhole, MatchCase:=True)
    If Not c Is Nothing Then 'found it
        c.Offset(0, 1).Value = DepartmentTextBox.Value
        c.Offset(0, 2).Value = VendorTextBox.Value
        c.Offset(0, 3).Value = ModelTextBox.Value
        c.Offset(0, 7).Value = LocationTextBox.Value
        c.Offset(0, 10).Value = RenewalAmountTextBox.Value
        c.Offset(0, 11).Value = Account1TextBox.Value
        c.Offset(0, 12).Value = Account1PmtsTextBox.Value
        c.Offset(0, 13).Value = Account2TextBox.Value
        c.Offset(0, 14).Value = Account2PmtsTextBox.Value
        c.Offset(0, 15).Value = Account3TextBox.Value
        c.Offset(0, 16).Value = Account3PmtsTextBox.Value
        c.Offset(0, 19).Value = ContactPhoneTextBox.Value
        c.Offset(0, 20).Value = ContactNameTextBox.Value
        c.Offset(0, 21).Value = ContactEmailTextBox.Value
        c.Offset(0, 22).Value = ApproverNameTextBox.Value
        c.Offset(0, 23).Value = ApproverEmailTextBox.Value
        c.Offset(0, 9).Value = CommentsTextBox.Value
 
    End If
End With
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top