Comparison cell by cell

Joined
May 29, 2014
Messages
33
Hi.

I have two columns "A1:A525" and "B1:B4339". I would like to know how can I get the value from "A1" and compare with all the values from column "B". I keep the line until the end of the "A" column. It would be something like this.

Column AColumn B
Company1company99
Company2company50
Company3Company1

<tbody>
</tbody>


So, I would take the first data from the column "A" which is "Company1" and compare with all values from the column "B" to look for cells with the same value.Lets imagine that it was found the duplicate value as you can see in the table below. Then I would like only to mark the company that was found and keep looping.

Here what I got. I dont know how to go through all the datas from colum "A" one by one.
My code look for all datas in column B and when it founds the data I go to the Column A and change the color of the company that was found.


Code:
lastrow = Sheets(1).Cells(Sheets(1).Rows.Count, "B").End(xlUp).Row


For i = 1 To lastrow


If Sheets(1).Cells(i, 2).Value = "Company1" Then


Msgbox "Company found"



End If


Next

Please, I would be very thankful if you could give me only a tip of how to do that,

thank you very much,

Alexandre
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

Try this code


Code:
Sub Find_It()
Dim lastrow As Long, MyRange As Range
Dim c As Range, Found As Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row#
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
    Set Found = Columns(2).Find(c.Value, LookIn:=xlValues, LookAt:=xlWhole)
If Not Found Is Nothing Then
    c.Font.Color = vbRed
End If
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,206,834
Messages
6,075,134
Members
446,123
Latest member
junkyardforme

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