User form is adding new entry instead of changing the existing one

Henrybukowski

New Member
Joined
Apr 16, 2013
Messages
29
I have a user form transferring data to a new line in a spreadsheet. It's something like as follows:


Code:
Private Sub CB1_Click()Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DataDump")
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myrng As Range
Dim myCell As Range


'''find  first empty row in database
''iRow = ws.Cells(Rows.Count, 1) _
''  .End(xlUp).Offset(1, 0).Row
'revised code to avoid problems with Excel tables in newer versions
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    


'copy the data to the database
ws.Cells(iRow, 1).Value = Me.cboDATE.Value
ws.Cells(iRow, 2).Value = Me.cboREF.Value
ws.Cells(iRow, 3).Value = Me.cboCI.Value
' Repeat for every text box which needs adding

I have added a function to update existing data entries. when a user clicks on the active line, the data from the active line is put back into the user form, so that the user can change and update the data:


Code:
Private Sub UserForm_Initialize()'read the data from active row
    With Me
        .fd1.Value = Cells(ActiveCell.Row, "X").Value
        .fd2.Value = Cells(ActiveCell.Row, "Y").Value
        .fd3.Value = Cells(ActiveCell.Row, "Z").Value

However, at the moment instead of updating the same record, my code is adding a whole new entry.

could any suggest a modification which makes it so that this function replaces the existing entry?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
When you say "I have added a function to update existing data entries. when a user clicks on the active line, the data from the active line is put back into the user form, so that the user can change and update the data:" - What exactly are the users clicking on? Can you provide any code you're using for it? It should be easy to determine the destination for the new data if we can determine where the old data needs to come from to populate your userform objects.

(Make sense?)
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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