Check if two Listobjects are same size

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
950
Office Version
  1. 2019
Platform
  1. Windows
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
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
 
Upvote 0

Forum statistics

Threads
1,214,891
Messages
6,122,105
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top