Consulting

Results 1 to 2 of 2

Thread: Run time error 424 object required

  1. #1

    Run time error 424 object required

    good day seniors.
    please any help on this ...

    Run time error 424
    Object Required

    Sub show_data()
    
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("Product_Master")
    
    Dim lr As Integer
    lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))
    
    If lr = 1 Then lr = 2
    
    With Me.ListBox2
        .ColumnCount = 4
        .ColumnHeads = True
        .ColumnWidths = "50,180,100,150"
        .RowSource = "Product_Master!A2:D" & lr
        
    End With
    
    End Sub
    
    
    Private Sub UserForm_Activate()
    Call show_data
    End Sub
    
    
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        Call frm_Inventory_management.Add_Product_List
        Call frm_onventory_management.show_inventory
    
    End Sub
    Attached Files Attached Files

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    All three subs refer to Objects. I don't know where the Error is happeniong.

    Declaring Row and Column Counters as Integers is setting up an error. Use Longs.

    I don't know who first came up with the idea that CountA was a good way to find the Last Row. Use Cells(Rows.Count, "A").End(xlUp).Row when you can guarantee that a particular column does actually extend to the bottom of a set of Columns.

    For a non Rectangular Table, use:
    Function RealLastRow(WsName As String) As Long
    Dim LastFormula      As Range
    Dim LastValue        As Range
    
    
    With Worksheets(WsName)
       On Error Resume Next
       Set LastFormula = .Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlFormulas, _
                         LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
       Set LastValue = .Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlValues, _
                       LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
       On Error GoTo 0
    End With
       
       If LastFormula Is Nothing And LastValue Is Nothing Then
          RealLastRow = 1
          Exit Function
       End If
       
       RealLastRow = Application.WorksheetFunction.Max(LastFormula.Row, LastValue.Row)
    End Function
    Sorry, I didn't record the author's name
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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