VBA data compare

newbie777

New Member
Joined
Oct 17, 2018
Messages
24
Hi all,

this is my first post so pardon me if it is not complete. You can ask me for more info if needed.

So i have basically data in consecutive rows that i need to compare with data in a column

If the data of each cell in each row exists in the column, then i need the row to be red. Obviously, if one missing cell, i need it to be green.

The data that i need to check is from C10:BN300
The column that i need to check against is BX:BX

Please note that i need to check each cell in each row against this column as every row is treated. And the aim is to check if this row is all good or not.


Can anyone please help me with this?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Let me see if i understand this correctly , I will make example with smaller data for size purposes



ABCDEFGHI
1
2AABBCCDDEEthis row would be redAA
3PPQQRRSSTTthis row would be greenBB
4AABBQQPPSSthis row would be redCC
5DD
6EE
7PP
8QQ
9SS

<tbody>
</tbody>


is that correct?
 
Upvote 0
That is perfectly correct. If one cell is not matching any value in the column, then this is a false. Instead of coloring the row, if we can put in column G TRUE or FALSE beside each row. Then this would be even better.

Many thanks!
 
Upvote 0
Alright got this for you... tested and works for me lol

Code:
Sub Newbie777()
Dim r As Range
Dim rLoc, curCount, lastr As Integer
rLoc = 10
lastr = ActiveSheet.Cells(ActiveSheet.Rows.Count, "C").End(xlUp).Row
Do While rLoc <= lastr
curCount = 0
For Each r In Range("C" & rLoc & ":BN" & rLoc)
    If Application.WorksheetFunction.CountIf(Range("BX:BX"), r.Value) > 0 Then
        curCount = curCount + 1
    End If
Next r
If curCount = 64 Then
Range("BO" & rLoc).Value = "True"
Else
Range("BO" & rLoc).Value = "False"
End If
rLoc = rLoc + 1
Loop


End Sub

Remember to save your file before doing this or trying it in a copy of the original
 
Last edited:
Upvote 0
you could also try this if the data will always be up to row 300

Code:
Sub Newbie777()
Dim r As Range
Dim rLoc, curCount, lastr As Integer
rLoc = 10
lastr = 300
Do While rLoc <= lastr
curCount = 0
For Each r In Range("C" & rLoc & ":BN" & rLoc)
    If Application.WorksheetFunction.CountIf(Range("BX:BX"), r.Value) > 0 Then
        curCount = curCount + 1
    End If
Next r
If curCount = 64 Then
Range("BO" & rLoc).Value = "True"
Else
Range("BO" & rLoc).Value = "False"
End If
rLoc = rLoc + 1
Loop




End Sub
 
Upvote 0
Thank you so much.

However, for some reason it flags everything as false.
I have one row that has NasdaQ stock Exchange which is present in the column but it shows it as false.
 
Upvote 0
Hmmm try verifying that on both the row and the column they are identical... meaning no extra spaces at the end or the beginning and that the capitalization is the same... if you dont wanna check all of them, which i understand as it is alot of data, ill try and modify it to check those as well.. give me a sec
 
Upvote 0
try this one out

Code:
Sub Newbie777()
Dim r As Range
Dim rLoc, curCount, lastr As Integer
Dim bx As Range
Dim lastbx As Integer
lastbx = ActiveSheet.Cells(ActiveSheet.Rows.Count, "BX").End(xlUp).Row
For Each bx In Range("BX1:BX" & lastbx)
    bx.Value = Trim(bx.Value)
Next bx

rLoc = 10
lastr = 300
Do While rLoc <= lastr
curCount = 0
For Each r In Range("C" & rLoc & ":BN" & rLoc)
    If Application.WorksheetFunction.CountIf(Range("BX:BX"), r.Value) > 0 Then
        curCount = curCount + 1
    End If
Next r
If curCount = 64 Then
Range("BO" & rLoc).Value = "True"
Else
Range("BO" & rLoc).Value = "False"
End If
rLoc = rLoc + 1
Loop


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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