Dear Experts
My codes displays following error message
Run-time error '424'
Object required
Please findout error and modify
Private Sub CmdSave2_Click() Dim a As Integer, lastrow As Integer, rowno As Integer, mysno As Integer, mydate As Date, response With Sheets("Input") Let mysno = ActiveSheet.Range("D5") Let mydate = ActiveSheet.Range("F5") End With With Sheets("Weights") For a = 1 To .Range("B" & .Rows.Count).End(xlUp).Row If .Cells(a, 2).Value = mysno And .Cells(a, 12).Value = mydate Then rowno = a End If Next a End With ' current record Not found If rowno = 0 Then Dim irow As Long Dim ws As Worksheet Set wsd = Worksheets("Weights") Set wsf = Worksheets("input") 'find first empty row in database irow = wsd.Cells(Rows.Count, 1) _ .End(xlUp).Offset(1, 0).Row MsgBox (CStr(irow)) 'copy the data to the database wsd.Cells(irow, 2).Value = wsf.Range("D5").Value wsd.Cells(irow, 3).Value = wsf.Range("D5").Value MsgBox "Saved" End If If rowno <> 0 Then ' current record found ' update the database wsd.Cells(rowno, 2).Value = wsf.Range("D5").Value wsd.Cells(rowno, 3).Value = wsf.Range("D5").Value MsgBox "Updated" End If End Sub
Your problem is due to the variable 'wsd' and 'wsf' that you set in the 'if rowno = 0' and then if you have rowno different from zero you won't set variables.
Move the code:
before the line:Set wsd = Worksheets("Weights") Set wsf = Worksheets("input")
I hope it helps.If rowno = 0 Then
Regards,
Antonio
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks