Comparing every row of sheet 2 with all rows of sheet 1

Hardyman

New Member
Joined
Jun 29, 2012
Messages
4
I have trouble trying to write a short program for this tedious work.</SPAN>
The rows contain the number indicated by Ys. For example In Sheet 1 Row 01 has number 02,03 and 06.</SPAN>
What I wanted to do is to compare the rows of numbers in sheet 2 with every 5 rows of numbers in sheet 1. Actually sheet 2 has as many as 200 over rows but I have only shown 9 rows here. If any one number (not necessary all 3 numbers) of sheet 2 matches at least one number in every row of sheet 1, that row in sheet 2 is then inserted in sheet 3.</SPAN>
Row 05 of sheet 2 has at least one number match a number of every 5 rows of sheet 1. So are Row 06 and Row 09 of sheet 2. </SPAN>
Please help.</SPAN>
Sheet1

*ABCDEFGHIJK
1*01020304050607080910
2Row01*YY**Y****
3Row02**YY***Y**
4Row03*Y******YY
5Row04****Y*Y**Y
6Row05Y****Y*Y**

<COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 71px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"></COLGROUP><TBODY>
</TBODY>


Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4


Sheet2

*ABCDEFGHIJK
1*01020304050607080910
2Row01*Y**Y**Y**
3Row02Y**Y**Y***
4Row03Y****Y**Y*
5Row04*YY***Y***
6Row05***Y*Y***Y
7Row06**Y****Y*Y
8Row07*Y**Y***Y*
9Row08**Y***YY**
10Row09Y*Y******Y

<COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 49px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"></COLGROUP><TBODY>
</TBODY>


Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4


Sheet3

*ABCDEFGHIJK
1*01020304050607080910
2Row05***Y*Y***Y
3Row06**Y****Y*Y
4Row09Y*Y******Y

<COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 52px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"><COL style="WIDTH: 26px"></COLGROUP><TBODY>
</TBODY>


Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1" target="_blank"> Excel Jeanie HTML 4
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi,
try using the macro (in Sheet2) for Your Data (Your Example):
Code:
Sub FindRows()
Dim x&, i&, j&, k&

ReDim tbl(1 To 5)

tbl(1) = "2,3,6"
tbl(2) = "3,4,8"
tbl(3) = "2,9,10"
tbl(4) = "5,7,10"
tbl(5) = "1,6,8"

x = 1
For i = 2 To 10
ReDim tbls(1 To 5)
   
   For j = 1 To 5
      tbla = Split(tbl(j), ",")
      For k = 0 To 2
        If Cells(i, CSng(tbla(k)) + 1).Value = "Y" Then
          tbls(j) = 1
          Exit For
        End If
      Next k
   Next j
   
If Application.Sum(tbls) = 5 Then
  x = x + 1
  WorkSheets("Sheet3").Range("B" & i & ":K" & i).Copy Range("M" & x)
End If
  
Next i
End Sub
Best regards.
 
Last edited:
Upvote 0
hurgadion, thank you for replying. Initially I got variable not defined tbla. I corrected it by adding Dim tbla and ran the code in sheet 2. Nothing happened.
 
Upvote 0
OK,
I understand rather, where is the mistake, try change the line
Code:
WorkSheets("Sheet3").Range("B" & i & ":K" & i).Copy Range("M" & x)
on the line
Code:
Range("B" & i & ":K" & i).Copy WorkSheets("Sheet3").Range("A" & x)
Best regards.
 
Upvote 0

Forum statistics

Threads
1,207,090
Messages
6,076,519
Members
446,211
Latest member
b306750

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