need a macro

JasonLeVan

Board Regular
Joined
Feb 7, 2011
Messages
121
I need a macro to compare columns c and d if they are not the same i need it to copy that row to sheet2 starting row 5. thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try

Code:
Sub CopyRows()
Dim LR As Long, LR2 As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    If Range("C" & i).Value <> Range("D" & i).Value Then
        LR2 = WorksheetFunction.Min(5, Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Row + 1)
        Rows(i).Copy Destination:=Sheets("Sheet2").Range("A" & LR2)
    End If
Next i
End Sub
 
Upvote 0
Try this out first.

Place in a cell the formula countif and select the first cell in the first column and then the whole of the second column in the next step of the formula, then fill going down, this will give you a number and if only 1 then add a filter to show only 1 then you can copy the rows or cells.

If this works then you can record a macro to do most of this automatically.
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

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