problem comparing rows and copying result to another sheet

mehdoush

New Member
Joined
Feb 23, 2009
Messages
21
i have a problem with macro that compares rows here's how it should work
if row starts with t76 then comapre row t76 with other rows (t75, t74), i want the macro to compare like follows :

if Connector1 and Connector2 from t76 are the same Connector1 and Connector2 from other families (t75,t76) then then copy these rows to sheet "Result".


here's an example :

family connector1 connector2

<TABLE style="WIDTH: 296pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=394 border=0 x:str><COLGROUP><COL style="WIDTH: 60pt" span=2 width=80><COL style="WIDTH: 88pt; mso-width-source: userset; mso-width-alt: 4278" span=2 width=117><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: silver; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left width=80 height=17>t76</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 60pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right width=80 x:num>12</TD><TD class=xl22 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 88pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left width=117 x:str="110251_00 ">110251_00 </TD><TD class=xl22 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 88pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left width=117 x:str="162995_00 ">162995_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #cc99ff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t74</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>14</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="110251_00 ">110251_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162995_00 ">162995_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #cc99ff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t74</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>100</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162994_00 ">162994_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="168209_00 ">168209_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: silver; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t76</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>141</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162994_00 ">162994_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="168209_00 ">168209_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: silver; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t76</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>12</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162994_00 ">162994_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="168209_00 ">168209_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #ccccff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t75</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>11</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162994_00 ">162994_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="168209_00 ">168209_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #ccccff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t75</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>11</TD><TD class=xl22 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left x:str="110251_00 ">110251_00 </TD><TD class=xl22 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left x:str="162995_00 ">162995_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #ccccff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t75</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>145</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162995_00 ">162995_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>168209_01</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #ccccff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t75</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>114</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162995_00 ">162995_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left>168209_02</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #ccccff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t75</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>12</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162995_00 ">162995_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="110251_00 ">110251_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #cc99ff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t74</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>12</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="168209_00 ">168209_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="110251_00 ">110251_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #ccccff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t75</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>12</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="168209_00 ">168209_00 </TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=left x:str="162994_00 ">162994_00 </TD></TR></TBODY></TABLE>

the result in sheet "result"

<TABLE style="WIDTH: 240pt; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=0 width=320 border=0 x:str><COLGROUP><COL style="WIDTH: 60pt" span=4 width=80><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: silver; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left width=80 height=17>t76</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 60pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right width=80 x:num>12</TD><TD class=xl24 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 60pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left width=80 x:str="110251_00 ">110251_00 </TD><TD class=xl24 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 60pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left width=80 x:str="162995_00 ">162995_00 </TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BACKGROUND: #ccccff; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 12.75pt; mso-ignore: style; mso-pattern: auto none" align=left height=17>t75</TD><TD style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" align=right x:num>11</TD><TD class=xl24 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left x:str="110251_00 ">110251_00 </TD><TD class=xl24 style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: #99cc00" align=left x:str="162995_00 ">162995_00 </TD></TR></TBODY></TABLE>
original post :

http://www.excelforum.com/excel-pro...ying-result-to-another-sheet.html#post2058528
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi,

You may have to change the sheet names to your sheet name. This is based on best guess for what you posted.
Copy and paste to a module.

Code:
Sub test4()
'' NoDupes came from John W's web'' thanks to him''
Dim AllCells As Range
Dim Cell As Range
Dim NoDupes As New Collection
Dim Lrow As Long
Dim Myval As Integer
Lrow = Sheets("Sheet1").Range("C65536").End(xlUp).Row
Set AllCells = Range("c2:c" & Lrow)
For Each Cell In AllCells
    On Error Resume Next
    NoDupes.Add Cell.Value, CStr(Cell.Value)

    Next Cell
    On Error GoTo 0
    For Each Item In NoDupes
    Range("A1:d1").Select
        Selection.AutoFilter
        With Selection
            .AutoFilter Field:=3, Criteria1:=Item '' this set the filtered data for the value
        End With
            Set Rng = ActiveSheet.AutoFilter.Range
            '' make sure you have more than 1 row to copy ''
            Myval = Range("c2:c" & Lrow).SpecialCells(xlCellTypeVisible).Count
            If Myval <> "1" Then
                Rlrow = Sheets("Result").Range("A65536").End(xlUp).Row + 1
                    Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1).Copy
                        Sheets("Result").Cells(Rlrow, 1).PasteSpecial xlValue
                    Application.CutCopyMode = xlCopy
            End If
    Next Item
End Sub
 
Upvote 0
thanks CharlesH

but i get runtime error 1004 at this line :

Code:
   Set Rng = ActiveSheet.AutoFilter.Range

regards
 
Upvote 0
Run time error may have beeb caused by the "Rng" not having a variable.

See if this helps
Code:
Sub test4()
'' NoDupes came from John W's web'' thanks to him''
Dim AllCells As Range, Rng As Range
Dim NoDupes As New Collection
Dim Lrow As Long
Dim Myval As Integer
Lrow = Sheets("Sheet1").Range("C65536").End(xlUp).Row
Set AllCells = Range("c2:c" & Lrow)
For Each Cell In AllCells
    On Error Resume Next
    NoDupes.Add Cell.Value, CStr(Cell.Value)

    Next Cell
    On Error GoTo 0
    For Each Item In NoDupes
    Range("A1:d1").Select
        Selection.AutoFilter
        With Selection
            .AutoFilter Field:=3, Criteria1:=Item '' this set the filtered data for the value
        End With
            Set Rng = ActiveSheet.AutoFilter.Range
            '' make sure you have more than 1 row to copy ''
            Myval = Range("c2:c" & Lrow).SpecialCells(xlCellTypeVisible).Count
            If Myval <> "1" Then
                Rlrow = Sheets("Result").Range("A65536").End(xlUp).Row + 1
                    Rng.Offset(1, 0).Resize(Rng.Rows.Count - 1).Copy
                        Sheets("Result").Cells(Rlrow, 1).PasteSpecial xlValue
                    Application.CutCopyMode = xlCopy
            End If
    Next Item
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,533
Messages
6,114,179
Members
448,554
Latest member
Gleisner2

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