Updating Data From UserForm

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I have a form that is pulling data from a worksheet, contingent upon the selection made from a combobox. I've coded other forms to update worksheets, but I'm struggling to find anything that makes sense, that guides me on how to code so that when a command button is clicked, the data sheet is updated on the same row where the combobox value is found. Example: If I have 5 names (Bob, Tom, Jim, Dave, Harry) and Bob is selected from the combobox. The User updates some data that is presented in the form. I want the updated data elements to update on the worksheet, when the User clicks a command button.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
How are you populating the userform based on the selected name in the combobox?
 
Upvote 0
If you choose "Bob" from the Combobox where should we search for "Bob"

Should we search column A B C or which column.

I suspect you should give us more details. I believe this is just one part of a larger script your working on.
And more questions will follow.
 
Upvote 0
Here is the code that retrieves the data. Not sure if I did the code tags correctly or not.
Code:
Private Sub cobo_Name_DropButt*******()


Dim i As Long
Dim LastRow As Long


LastRow = Sheets("Client Info").Range("F" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow


If Sheets("Client Info").Cells(i, "F").Value = (Me.cobo_Name) Or _
Sheets("Client Info").Cells(i, "F").Value = Val(Me.cobo_Name) Then
    Me.txt_First = Sheets("Client Info").Cells(i, "C").Value
    Me.txt_Last = Sheets("Client Info").Cells(i, "D").Value
    Me.txt_Suffix = Sheets("Client Info").Cells(i, "E").Value
    Me.txt_Phone = Sheets("Client Info").Cells(i, "K").Value
    Me.txt_Email = Sheets("Client Info").Cells(i, "L").Value
    Me.txt_DPStart = Sheets("Client Info").Cells(i, "M").Value
    Me.txt_DCStart = Sheets("Client Info").Cells(i, "N").Value
    Me.txt_OCStart = Sheets("Client Info").Cells(i, "O").Value
    Me.txt_CTIStart = Sheets("Client Info").Cells(i, "P").Value
    Me.txt_CTOStart = Sheets("Client Info").Cells(i, "Q").Value


End If
Next
End Sub
 
Upvote 0
In that code you are searching column F for the name selected in the combobox using a loop to go through the rows.

When/if you find the name the loop variable i will be the row in which you've found the name, so you can use that variable/value to write back update the row the name was found in.
 
Upvote 0
Thank you Norie! That was what I was struggling with...how to update the same row, from a different piece of code. As you can see, I'm still new to VBA, but with help like yours, I'm navigating it. Thank you again!
 
Upvote 0

Forum statistics

Threads
1,223,104
Messages
6,170,125
Members
452,303
Latest member
c4cstore

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