Compare two columns

G

Guest

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.
 
G

Guest

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.
 
G

Guest

Bob I said:
Columns are going down the sheet, are you sure you don't mean comparing
rows?


Here's a macro I copied from another spreadsheet.....I was trying to modify it
Sub CheckInvNos()

' Macro recorded 5/9/2007 by Pam Michalk

'Enter starting column and heading row for the bottom section which will
have rows cut
sCheckCol = "G"
nCheckRow = 15772

'Enter the starting column and heading row for the top section which
will be compared
sCompareCol = "A"
nCompareStart = 1

nCompareRow = nCompareStart
sCompare = sCompareCol & nCompareRow

bContinue = True

Do While bContinue
nCheckRow = nCheckRow + 1
sCheck = sCheckCol & nCheckRow
Range(sCheck).Select
sInvNo = Selection.Value

nCompareRow = nCompareStart

If IsEmpty(sInvNo) Then
bContinue = False
Else
bCompare = True
Do While bCompare
nCompareRow = nCompareRow + 1
sCompare = sCompareCol & nCompareRow
Range(sCompare).Select
sCompInvNo = Selection.Value

If sInvNo = sCompInvNo Then
Range(sCheck).Select
Selection.EntireRow.Cut
Sheets("Sheet3").Select
ActiveSheet.Paste
nCheckRow = nCheckRow + 1
bCompare = False
ElseIf IsEmpty(sCompInvNo) Then
bCompare = False
End If
Loop
End If
Loop
End Sub

Thanks.
 
B

Bob I

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top