Update Spreadsheet Data with userform

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,066
Office Version
  1. 2016
Platform
  1. Windows
I have as spreadsheet that shows its data in a userform listbox, when the data is selected from the listbox and the edit button is clicked it opens up a second userform CustEditForm and populates the texboxes. This bit is fine

This is the code that does this
Code:
Private Sub CommandButton2_Click()

'Yes/No Message Box
Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String
    QuestionToMessageBox = "Are you sure you want to edit this Customer Record?"
    YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "Add New Products")
If YesOrNoAnswerToMessageBox = vbYes Then

'Loadsform with data
Load CustEditForm
    With CustEditForm
        .DateTB.Text = ListBox1.List(ListBox1.ListIndex, 1)
        .IDTB.Text = ListBox1.List(ListBox1.ListIndex, 1)
        .BusNameTB.Text = ListBox1.List(ListBox1.ListIndex, 2)
        .NameContactTB.Text = ListBox1.List(ListBox1.ListIndex, 3)
        .AddressNoTB.Text = ListBox1.List(ListBox1.ListIndex, 4)
        .StreetTB.Text = ListBox1.List(ListBox1.ListIndex, 5)
        .AreaTB.Text = ListBox1.List(ListBox1.ListIndex, 6)
        .CityTB.Text = ListBox1.List(ListBox1.ListIndex, 7)
        .PostCodeTB.Text = ListBox1.List(ListBox1.ListIndex, 8)
        .TelephoneTB.Text = ListBox1.List(ListBox1.ListIndex, 9)
        .MobileTB.Text = ListBox1.List(ListBox1.ListIndex, 10)
        .FaxTB.Text = ListBox1.List(ListBox1.ListIndex, 11)
        .EmailTB.Text = ListBox1.List(ListBox1.ListIndex, 12)
        
        
    ListBox1.List(ListBox1.ListIndex, 1) = CustEditForm.DateTB.Text
    ListBox1.List(ListBox1.ListIndex, 2) = CustEditForm.IDTB.Text
    ListBox1.List(ListBox1.ListIndex, 3) = CustEditForm.BusNameTB.Text
    ListBox1.List(ListBox1.ListIndex, 4) = CustEditForm.NameContactTB.Text
    ListBox1.List(ListBox1.ListIndex, 5) = CustEditForm.AddressNoTB.Text
    ListBox1.List(ListBox1.ListIndex, 6) = CustEditForm.StreetTB.Text
    ListBox1.List(ListBox1.ListIndex, 7) = CustEditForm.AreaTB.Text
    ListBox1.List(ListBox1.ListIndex, 8) = CustEditForm.CityTB.Text
    ListBox1.List(ListBox1.ListIndex, 9) = CustEditForm.PostCodeTB.Text
    ListBox1.List(ListBox1.ListIndex, 10) = CustEditForm.TelephoneTB.Text
    ListBox1.List(ListBox1.ListIndex, 11) = CustEditForm.MobileTB.Text
    ListBox1.List(ListBox1.ListIndex, 12) = CustEditForm.FaxTB.Text
    
    End With
    CustList.Hide
    
    End If

End Sub

The second userform has a submit button, but i can't workout the code to update the data without creating a extra record in my worksheet called CustDetails . I am not creating a new record, only updating exsisting records.

I've been stuck on this for a few weeks now. could someone please have a look

Thanks
 
Last edited:

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I'm really stuck on this one could some please help
 
Upvote 0
Me again, jusr posting on my thread. can anyone help me with this problem.

Thanks
 
Last edited:
Upvote 0
Hi

Only me

I'm still stuck on this one for a few weeks now can someone please help. What i need is that when the userform is populated from a sheet it save the date back into the sheet in the same row the data came from. A new record is not created, it only updates the record.

I have been stuck on this for a few weeks now
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,708
Messages
6,174,005
Members
452,542
Latest member
Bricklin

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