Need VBA to validate and compare 2 sheets

mpatino

Board Regular
Joined
Jul 8, 2009
Messages
82
Hi Guys,

I really need help from a VBA expert, I have 2 sheets that need some comparison, but before the comparison I need to exclude some lines that contain certain values, I have created the following formula but as you can imagine, running this formula takes forever in a 6k records spread sheet:

{=IF(SUMPRODUCT(--(NOT(ISERR(SEARCH({" ","-"},A2)))))>0,"",IF(SUMPRODUCT(--(NOT(ISERR(SEARCH({"TV","Limited","Training","Trail","Loan","Test","Leaf","kiosk","no Scanning","Video training"},B2)))))>0,"",IF(MATCH(A2&C2,Sheet3!A:A&Sheet3!B:B,0),"Both",IF(MATCH(Sheet2!A2,Sheet3!A:A,0),"SN Only",IF(MATCH(Sheet2!C2,Sheet3!B:B,0),"HN Only","No Match")))))}

Besides that I am not getting validation for some part of the formula (marked in bold), below is an example of how my spreadsheets look like (not all columns are included only the ones I use for validation)

Sheet 1

[TABLE="class: outer_border, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]Serial number[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]System name[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Computer Name[/TD]
[TD]Validation[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial-0000001[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]Tv room[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 1[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000002[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]Limited[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 2[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000003[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]Training room[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 3[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial 0000004[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 4[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial00000050[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 5[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000006[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 6[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial-0000007[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 7[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000008[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 8[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000009[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 9[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial 0000010[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 50[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000011[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 11[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000012[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 12[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000013[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]Trial[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 13[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000014[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 14[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000015[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 85[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000016[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 16[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]18[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial00000170[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 17[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]19[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000018[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 18[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]20[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000019[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]Loan[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 19[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]21[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000020[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]Loan[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 20[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000021[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Kiosk[/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 21[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]23[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000022[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 22[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]24[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial00000230[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 23[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000024[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 24[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]26[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000025[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 1000[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]27[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000026[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 26[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
[TR]
[TD]28[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="class: xl66, width: 95"]serial0000027[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][TABLE="width: 110"]
<tbody>[TR]
[TD="class: xl66, width: 110"]Computer 27[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Formula goes here[/TD]
[/TR]
</tbody>[/TABLE]

Sheet 2


[TABLE="class: outer_border, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial-0000001[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 1[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000002[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 2[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000003[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 3[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial 0000004[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 4[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000005[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 5[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000006[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 6[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial-0000007[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 7[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000008[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000009[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 9[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial 0000010[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 12[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000011[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 10[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000012[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD][TABLE="width: 95"]
<tbody>[TR]
[TD="width: 95"]serial0000013[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 108"]
<tbody>[TR]
[TD="width: 108"]Computer 13[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]18[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]19[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]20[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]21[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]23[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]24[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]25[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

The exclusions are taken out of sheet 1:

From serial number column, if there is a space (one or more) or a dash, the line is excluded, formula stops
From System name column if any of the following words or phrases are found on any of the cells, the line is excluded:
Lab
Test
Trial
Loan
Leaf warehouse
Kiosk
Tv rooms
Loaner
No scanning
Test device
Video training

I would really appreciate if someone could help me with a VBA solution.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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