PDA

View Full Version : [SOLVED:] Run time error 424 object required



GEORGE PERRY
03-12-2021, 05:15 AM
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

SamT
03-12-2021, 09:55 AM
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