Write data in the correct table row

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
224
Office Version
  1. 365
Platform
  1. Windows
I have a table with 42 columns and 10 rows with customer date in each row. I made a form in which the user can fill in all the textboxes and then save as a new row to this table. Works all fine.
No, a have a similar form in which and existing customer can be 'lifted' out of the table to make changes later, using a combobox. This also works fine.
Where I am stuck, is how to write all textboxes, some with updated content, back to the same row as where they came from.

below lists my latest attempt:
(CustomerData = the full table
SelectedClient = the range with company names used in the combobox to search the company to be edited))


Where do I go wrong?

VBA Code:
Private Sub btnSaveEditsCompany_Click()
    Dim CustomerData As Range
    Set CustomerData = Range("A6").CurrentRegion
    Dim clientRow As Long
    clientRow = Application.Match(CStr(selectedClient), CustomerData.Columns(5), 0)
    ' Wait for user to edit data and click the "Save" button
    ' Save edited data back into the table
            CustomerData.Cells(clientRow, 5).Value = txtClientCompanyName.Value
            CustomerData.Cells(clientRow, 6).Value = txtClientPhone.Value
            CustomerData.Cells(clientRow, 7).Value = txtClientWebsite.Value
            CustomerData.Cells(clientRow, 8).Value = txtSalesAgent.Value
            CustomerData.Cells(clientRow, 9).Value = txtClientAddress.Value
            CustomerData.Cells(clientRow, 10).Value = txtClientCity.Value
            CustomerData.Cells(clientRow, 11).Value = txtClientZip.Value
                        
            MsgBox "Client data has been updated.", vbInformation, "Success"
End Sub
 
Sorry to be unclear... the edited cells are placed on the wrong row, not on the row it came from

not unclear - did you try the updated code in #post 8?

If still having issues place copy of your workbook with dummy data in a file sharing site like dropbox & provide a link to it


Dave
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Yes, I did.
VBA Code:
Dim clientRow As Long

Private Sub UserForm_Initialize()
    With frm11_EditCompanyDetails
        Height = 800
        Width = 1000
    End With

So Dim clientRow on top of page,
and
VBA Code:
Private Sub btnSaveEditsCompany_Click()
    With ThisWorkbook.Worksheets("Customers")
            .Cells(clientRow, 5).Value = txtClientCompanyName.Value
            .Cells(clientRow, 6).Value = txtClientPhone.Value
 
Upvote 0
suggest that you place copy of your workbook with dummy data in a file sharing site like dropbox & provide a link to it - I can then understand what is happening in your project

Dave
 
Upvote 0
THank you... I'd rather not have it public though... not sure if MrExcel offers private mailboxes to its users?
 
Upvote 0
THank you... I'd rather not have it public though... not sure if MrExcel offers private mailboxes to its users?

Private support not allowed - Just anonymize the workbook (make a copy and remove all identifying particulars or details from it) and add some dummy data.


Dave
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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