Compare two tables in VBA

mr2bart

Board Regular
Joined
Dec 18, 2014
Messages
57
Hi,

I am stuck on one point.
I want to compare directly 2 VBA tables, I even do not know if possible: here code:

test1 = sheet(1).range("B2:f2")
test2 = sheet(2).range("C10:G10")

I want to compare test1 and and test2.

Can I do directly :
if test1 = test2 then
do something
endif

It seems it does not work.
Where is the problem?

Thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Something like
Code:
Sub Compare()
   Dim test1 As Variant, test2 As Variant
   test1 = Join(Application.Index(Sheets(1).Range("B2:f2").Value, 1, 0), "|")
   test2 = Join(Application.Index(Sheets(2).Range("C10:G10").Value, 1, 0), "|")
   If test1 = test2 Then
      MsgBox "OK"
   Else
      MsgBox "Not OK"
   End If
End Sub
 
Upvote 0
I have additionnal question to understand better. On Application.index(...), what's the meaning/function of ,1 and ,0 ?
Thanks
 
Upvote 0
I'll reopen this thread as I would like to do the same here but instead of comparing just one row (B2:F2) with another row (C10:G10) I would like to compare two whole tables (In different sheets) with range of one table A2:F300 and range of second table A2:F300, is this possible with an adaptation of the above code please?

Thanks in advance
 
Upvote 0
As this is a completely different question, you need to start a thread of your own. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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