Closed Thread
Results 1 to 2 of 2

Thread: Run-time error '424'

  1. #1
    Registered User
    Join Date
    05-03-2007
    Posts
    26

    Run-time error '424'

    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

  2. #2
    Forum Guru
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2003
    Posts
    1,241
    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:
       Set wsd = Worksheets("Weights")
       Set wsf = Worksheets("input")
    before the line:
    If rowno = 0 Then
    I hope it helps.

    Regards,
    Antonio

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0