I have now been going nuts for two days trying to get this to work-and its probably a simple fix
---Please help I am at my wits end, .
I have created a userform for a database of contacts, I have a combobox on the userform that pulls a company name from column A based on that selection a number of textboxes are populated with info from the related adjacent rows.
My issue is I would like to be able to edit the data in the textboxes and click a command button to update the related data.....I have got it to work for Column A only, the adjacent rows will not update with the changes.
Note:I cannot use the VLookup or Match to find the combobox value because the data in row A is not all unique (IE: multiple contacts from the same company = duplicate values in column A)
Here is the latest code I have been using, again rows in column A WILL change but the others revert back to the original state on command button click-- Please help.
Combobox name-Coname
Userform-Userform1
Worksheet-Metadata
Dim lngDataRow As Long
lngDataRow = UserForm1.Coname.ListIndex + 1
UserForm1.Contact.Value = Worksheets("Metadata").Range("J" & lngDataRow).Value
UserForm1.Phone.Value = Worksheets("Metadata").Range("C" & lngDataRow).Value
UserForm1.Fax.Value = Worksheets("Metadata").Range("D" & lngDataRow).Value
UserForm1.Email.Value = Worksheets("Metadata").Range("K" & lngDataRow).Value
UserForm1.Cellphone.Value = Worksheets("Metadata").Range("N" & lngDataRow).Value
UserForm1.Address.Value = Worksheets("Metadata").Range("E" & lngDataRow).Value
UserForm1.City.Value = Worksheets("Metadata").Range("H" & lngDataRow).Value
UserForm1.State.Value = Worksheets("Metadata").Range("I" & lngDataRow).Value
UserForm1.Zip.Value = Worksheets("Metadata").Range("G" & lngDataRow).Value
UserForm1.Scope.Value = CompName.Value & vbNewLine & Contact.Value & vbNewLine & Phone.Value & vbNewLine & Email.Value
Private Sub CBUpdate_Click()
Worksheets("Metadata").Range("C" & Coname.ListIndex + 1).Value = Me.Phone.Value
'Above and below, two different attempts
Worksheets("Metadata").Range("D" & Coname.ListIndex + 1).Value = Me("Fax").Value
Worksheets("Metadata").Range("K" & Coname.ListIndex + 1).Value = Me("Email").Value
Worksheets("Metadata").Range("N" & Coname.ListIndex + 1).Value = Me("Cellphone").Value
Worksheets("Metadata").Range("E" & Coname.ListIndex + 1).Value = Me("Address").Value
Worksheets("Metadata").Range("H" & Coname.ListIndex + 1).Value = Me("City").Value
Worksheets("Metadata").Range("I" & Coname.ListIndex + 1).Value = Me("State").Value
Worksheets("Metadata").Range("G" & Coname.ListIndex + 1).Value = Me("Zip").Value
---Please help I am at my wits end, .
I have created a userform for a database of contacts, I have a combobox on the userform that pulls a company name from column A based on that selection a number of textboxes are populated with info from the related adjacent rows.
My issue is I would like to be able to edit the data in the textboxes and click a command button to update the related data.....I have got it to work for Column A only, the adjacent rows will not update with the changes.
Note:I cannot use the VLookup or Match to find the combobox value because the data in row A is not all unique (IE: multiple contacts from the same company = duplicate values in column A)
Here is the latest code I have been using, again rows in column A WILL change but the others revert back to the original state on command button click-- Please help.
Combobox name-Coname
Userform-Userform1
Worksheet-Metadata
'select value from Combo box
Private Sub Coname_change()Dim lngDataRow As Long
lngDataRow = UserForm1.Coname.ListIndex + 1
' populate textboxes
Dim c As Range
UserForm1.CompName.Value = Worksheets("Metadata").Range("A" & lngDataRow).ValueUserForm1.Contact.Value = Worksheets("Metadata").Range("J" & lngDataRow).Value
UserForm1.Phone.Value = Worksheets("Metadata").Range("C" & lngDataRow).Value
UserForm1.Fax.Value = Worksheets("Metadata").Range("D" & lngDataRow).Value
UserForm1.Email.Value = Worksheets("Metadata").Range("K" & lngDataRow).Value
UserForm1.Cellphone.Value = Worksheets("Metadata").Range("N" & lngDataRow).Value
UserForm1.Address.Value = Worksheets("Metadata").Range("E" & lngDataRow).Value
UserForm1.City.Value = Worksheets("Metadata").Range("H" & lngDataRow).Value
UserForm1.State.Value = Worksheets("Metadata").Range("I" & lngDataRow).Value
UserForm1.Zip.Value = Worksheets("Metadata").Range("G" & lngDataRow).Value
UserForm1.Scope.Value = CompName.Value & vbNewLine & Contact.Value & vbNewLine & Phone.Value & vbNewLine & Email.Value
Private Sub CBUpdate_Click()
'Update cells in workbook with changed values
Worksheets("Metadata").Range("A" & Coname.ListIndex + 1).Value = Me.CompName.Value' **********Above is the only one that works
Worksheets("Metadata").Range("J" & Coname.ListIndex + 1).Value = Me.Contact.ValueWorksheets("Metadata").Range("C" & Coname.ListIndex + 1).Value = Me.Phone.Value
'Above and below, two different attempts
Worksheets("Metadata").Range("D" & Coname.ListIndex + 1).Value = Me("Fax").Value
Worksheets("Metadata").Range("K" & Coname.ListIndex + 1).Value = Me("Email").Value
Worksheets("Metadata").Range("N" & Coname.ListIndex + 1).Value = Me("Cellphone").Value
Worksheets("Metadata").Range("E" & Coname.ListIndex + 1).Value = Me("Address").Value
Worksheets("Metadata").Range("H" & Coname.ListIndex + 1).Value = Me("City").Value
Worksheets("Metadata").Range("I" & Coname.ListIndex + 1).Value = Me("State").Value
Worksheets("Metadata").Range("G" & Coname.ListIndex + 1).Value = Me("Zip").Value