Check if two Listobjects are same size

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
926
I am trying to develop a macro where I will be importing values from one Listobject to another Listobject.

Before pasting the values, I need to ensure that the two Listobjects are the same size, i.e. they have the same number of rows and columns.

If this is not the case, then the "new Listobject" (where values will be pasted) must be adjusted by the macro to have the same size as the "old Listobject" i.e. delete/add rows/columns accordingly.

I am currently using this code to paste the values which works fine.

Code:
Workbooks(cu_name).Names("import_admin_inputs").RefersToRange.Value2 = Workbooks(fn_name).Names("import_admin_inputs").RefersToRange.Value2
Any help would be much appreciated,
Andrew
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
44,644
Office Version
365
Platform
Windows
I need to ensure that the two Listobjects are the same size, i.e. they have the same number of rows and columns.
Could you adapt something like this?

Code:
Sub CompareListObjectSizes()
  Dim Lobj1 As ListObject, Lobj2 As ListObject
  
  Set Lobj1 = ActiveSheet.ListObjects(1)
  Set Lobj2 = ActiveSheet.ListObjects(2)
  
  If Lobj1.ListColumns.Count = Lobj2.ListColumns.Count And Lobj1.ListRows.Count = Lobj2.ListRows.Count Then
    MsgBox "Same size"
  Else
    MsgBox "Different size"
  End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,099,082
Messages
5,466,535
Members
406,485
Latest member
kaksolver

This Week's Hot Topics

Top