HI There,
I need your help with this issue:
sheet1
A B C
1 JHON ON1 2
2 FADI ON3 6
3 BRIAN ON4 5
4 MOHN ON9 2
5 ALEX ON6 7
sheet2
A B C
1 JHON ON1 2
2 BRIAN ON4 7
3 ALEX ON6 7
4 FADI ON3 8
I want sheet3 to be:
A B C
1 JHON ON1 2
2 FADI ON3 6
3 FADI ON3 8
4 BRIAN ON4 5
5 BRIAN ON4 7
6 MOHN ON9 2
7 ALEX ON6 7
I want macro to compare betwwen sheet1 and sheet2,
John & Alex were in both and same value in C col, copy to sheet three
Fadi & Brian were in both but different value in C col, copy row to sheet3 and fill the row copied from sheet2 with "green for example"
Mohn was only in sheet1, copy to sheet3
I have attached the file
Sorry being my question is long, but really I need help
Thanks in advance
Ziyadh
Hey Ziyadh,
You can use this code -Option Explicit Dim lrow As Long Dim strow As Long Dim erow As Long Dim i As Long Sub compare_files() Application.ScreenUpdating = False Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = "Temp" lrow = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row Worksheets("Sheet1").Range("A1:C" & lrow).Copy Worksheets("Temp").Range("A1") Worksheets("Temp").Range("D1:D" & lrow).Value = "1" lrow = Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row Worksheets("Sheet2").Range("A1:C" & lrow).Copy Worksheets("Temp").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) strow = Worksheets("Temp").Range("D" & Rows.Count).End(xlUp).Row erow = Worksheets("Temp").Range("A" & Rows.Count).End(xlUp).Row Worksheets("Temp").Range("D" & strow + 1 & ":D" & erow).Value = "2" ActiveWorkbook.Worksheets("Temp").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Temp").Sort.SortFields.Add Key:=Range("A:A") _ , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Temp").Sort .SetRange Range("A:D") .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With With Worksheets("Temp") .Rows("1:1").Insert lrow = .Range("A" & Rows.Count).End(xlUp).Row For i = lrow To 2 Step -1 If .Range("A" & i).Value = .Range("A" & i - 1).Value And .Range("B" & i).Value = .Range("B" & i - 1).Value And _ .Range("C" & i).Value = .Range("C" & i - 1).Value And .Range("D" & i).Value <> .Range("D" & i + 1).Value Then .Rows(i & ":" & i).Delete lrow = lrow - 1 ElseIf .Range("A" & i).Value = .Range("A" & i - 1).Value And .Range("B" & i).Value = .Range("B" & i - 1).Value And _ .Range("C" & i).Value <> .Range("C" & i - 1).Value And .Range("D" & i).Value <> .Range("D" & i + 1).Value Then .Range("A" & i - 1 & ":C" & i).Interior.Color = 65535 End If Next i End With Worksheets("Temp").Columns("D:D").Delete Application.ScreenUpdating = True End Sub
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks