0

The following code creates a compile time error message "type mismatch":

Private Sub Example  
    JustAdd(Sheet1.ListObjects("Table6"))
End Sub

Public Sub JustAdd(ByRef tableN As ListObject)  
   tableN.ListRows.Add
End Sub

Also tried:

Private Sub Example  
    Dim tmp As ListObject
    Set tmp = Sheet1.ListObjects("Table6")
    JustAdd(tmp)
End Sub

Public Sub JustAdd(ByRef tableN As ListObject)  
   tableN.ListRows.Add
End Sub

Also:

Private Sub Example  
    Dim tmp As ListObject
    tmp = Sheet1.ListObjects("Table6")
    JustAdd(tmp)
End Sub

Public Sub JustAdd(ByRef tableN As ListObject)  
   tableN.ListRows.Add
End Sub

Just need a quick nudge in the right direction to get this JustAdd subroutine working

Chrismas007
  • 6,085
  • 4
  • 24
  • 47
  • possible duplicate of [Passing array as argument to a Class setter using VB 6.0](http://stackoverflow.com/questions/19538094/passing-array-as-argument-to-a-class-setter-using-vb-6-0) – GSerg Jan 22 '15 at 19:47
  • Worth a read: http://www.cpearson.com/excel/byrefbyval.aspx – Tim Williams Jan 22 '15 at 20:24

1 Answers1

0

I only tried your first example but I believe any of them should work with this slight modification.

Call JustAdd(Sheet1.ListObjects("Table6"))

EDIT¹: OK, maybe not the third one.

EDIT²: More information at: Calling Sub and Function Procedures (Applies to: Office 2013 | VBA)

  • 4
    Don't you think it would be better to tell OP to drop the parenthesis rather than use an obsolete keyword from an ancient version of Excel Macros? (It's not even VBA.....) Perhaps some explanation about what is going on and *why* doing this works? – RubberDuck Jan 22 '15 at 19:08
  • 1
    @RubberDuck - Good advice. I've added a link to some current MSDN documentation on the subject. –  Jan 22 '15 at 19:20