Compare two columns
This will compare cells in A with cells in B in rows 1 thru 20 and if
they all match cut B1:B20 from sheet 1 and insert into column A of Sheet2.
Sub Macro2()
'
' Macro2 Macro
'
'
Sheets("Sheet1").Select
y = 0
For x = 1 To 20
LCell = "A" & x
RCell = "B" & x
If Range(LCell) = Range(RCell) Then
y = y + 1
End If
Next x
If y = 20 Then
Range("B1:B20").Select
Selection.Cut
Sheets("Sheet2").Select
Range("A1:A20").Select
Selection.Insert Shift:=xlToRight
Sheets("Sheet1").Select
Range("A1:A20").Select
End If
End Sub
pm wrote:
Hi Bob,
I actually have the data side by side in columns. I want to compare the two
and if there is a match, cut the 2nd column and paste it in a separate sheet.
Thanks.
"Bob I" wrote:
Columns are going down the sheet, are you sure you don't mean comparing
rows?
pm wrote:
I've got two columns that I'm trying to compare. If the 2nd column equals
the first then I want to cut the 2nd column and paste it into another column.
CK34041R IC 1
CK38711U IC 1
CMP-AS04S-SINGL SINGLE SPEAKER 1
CK38711U IC 0
CMP-AS04S-SINGL SINGLE SPEAKER 1
CMP-AS14 SPEAKER SET 1
Thanks.
|