PC Review


Reply
Thread Tools Rate Thread

Compare Data between 2 columns, Excel 2000 & 2003

 
 
jfcby
Guest
Posts: n/a
 
      12th Jul 2007
Hello,

My worksheet has in column1 numbers (001, 002, 003, etc) and column2
has same type of numbers. But, I need to compare beginning with
column1 cell1 and check each cell in column2 if there is a match. If
column1 cell has no match in column2 then I need to change column1
background color to red.

This is the code I have so far but I'm having trouble figuring out how
to check all of column2 cells if there is a match and then continuing
in column1 cells.

Sub CompareData2()
'Compare Column1 cell to all column2 cells
Dim rngC1 As Range
Dim rngC2 As Range
Dim cf As String
Set rngC1 = Range("C4:C65000")
Set rngC2 = Range("D465000")
With ActiveSheet
For Each c1 In rngC1
c1.Select
For Each c2 In rngC2
c2.Select
If c1.Value = c2.Value Then
MsgBox "MATCH" 'for test purpose
Exit For
Else
c1.Select
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If
Next
Next
End With
End Sub

Thank you for your help,
jfcby

 
Reply With Quote
 
 
 
 
=?Utf-8?B?ZXhjZWxlbnQ=?=
Guest
Posts: n/a
 
      12th Jul 2007
try:
Sub tst()
colC = Cells(65500, 3).End(xlUp).Row
colD = Cells(65500, 4).End(xlUp).Row
On Error GoTo om
For t = 4 To colD
rw = Range("D1" & colD).Find(Cells(t, 3), LookIn:=xlValues).Row
Next
End
om:
Cells(t, 3).Interior.ColorIndex = 3
Resume Next
End Sub


"jfcby" skrev:

> Hello,
>
> My worksheet has in column1 numbers (001, 002, 003, etc) and column2
> has same type of numbers. But, I need to compare beginning with
> column1 cell1 and check each cell in column2 if there is a match. If
> column1 cell has no match in column2 then I need to change column1
> background color to red.
>
> This is the code I have so far but I'm having trouble figuring out how
> to check all of column2 cells if there is a match and then continuing
> in column1 cells.
>
> Sub CompareData2()
> 'Compare Column1 cell to all column2 cells
> Dim rngC1 As Range
> Dim rngC2 As Range
> Dim cf As String
> Set rngC1 = Range("C4:C65000")
> Set rngC2 = Range("D465000")
> With ActiveSheet
> For Each c1 In rngC1
> c1.Select
> For Each c2 In rngC2
> c2.Select
> If c1.Value = c2.Value Then
> MsgBox "MATCH" 'for test purpose
> Exit For
> Else
> c1.Select
> With Selection.Interior
> .ColorIndex = 3
> .Pattern = xlSolid
> End With
> End If
> Next
> Next
> End With
> End Sub
>
> Thank you for your help,
> jfcby
>
>

 
Reply With Quote
 
jfcby
Guest
Posts: n/a
 
      13th Jul 2007
Hello excelent,

Your code give me a starting point to work with. I called your code
from a modeless userform and it closed my form when it finished. If I
deleted End then it continued changing the cell background color to
red past the last cell with data. So to fix this I added a If Then
GoTo statement example below.

[macro]

Sub CompareData3()
With ActiveSheet
ColA = Cells(65500, 1).End(xlUp).Row 'changed
ColB = Cells(65500, 2).End(xlUp).Row 'changed
On Error GoTo om
For t = 4 To ColB 'changed
If t > ColA Then GoTo es 'added
rw = Range("B4:B" & ColB).Find(Cells(t, 1),
LookIn:=xlValues).Row 'changed
Next
'deleted End
om:
Cells(t, 1).Interior.ColorIndex = 3
Resume Next
End With
es: 'added
End Sub

[/macro]

 
Reply With Quote
 
jfcby
Guest
Posts: n/a
 
      13th Jul 2007
Hello excelent,

Thank you for your help and code!

jfcby

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare two columns of texts in Excel 2003 K Microsoft Excel Misc 7 23rd Sep 2009 02:36 PM
Split Data 1 Column to 3 columns, Excel 2000 & 2003 jfcby Microsoft Excel Programming 2 17th Mar 2007 09:16 PM
Need help using VBA to compare data in Excel columns, then manipulating data Sam Hill Microsoft Excel Programming 0 8th May 2006 05:55 PM
How can I compare data in 2 different columns in Excel? =?Utf-8?B?THVja3k=?= Microsoft Excel Misc 2 14th Oct 2004 03:05 PM
Compare Two Columns of Data Using VB Excel willik Microsoft Excel Programming 2 1st Mar 2004 02:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:35 PM.