Compare two cell and do green color if 80% text matches

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
157
Hi Can any one help me on this? i have below data which need to compare with the next row and give green color if 80% text matches

image removed

i have written below code but excel is getting hang whenever i run the Macro

sub colorr()

Set shgroup = ThisWorkbook.Worksheets("Grouping Data_Underwriters")


lastrow1 = shgroup.Range("B" & Rows.Count).End(xlUp).Row


Range("B2").Select


For U = 2 To lastrow1

Set MYNAME2 = Cells(U, "B")
Set MYNAME3 = Cells((U + 1), ("B"))
MY = Left(MYNAME2, Len(MYNAME2) * 0.8)

x = Len(MY)
y = Left(MYNAME3, x)
If y = MY Then


shgroup.Cells(U, "B").Interior.Color = vbGreen
shgroup.Cells(U + 1, "B").Interior.Color = vbGreen


End If


Next U

END SUB
 
Last edited by a moderator:
Just want to understand and if you can check that why is it doing green color on below name even text is not matching 80% text
[TABLE="class: cms_table, width: 235"]
<tbody>[TR]
[TD]JOHNSONNOIL[/TD]
[/TR]
[TR]
[TD]JOHNSONNOILANUNITEDGENERALPARTNERSHIP[/TD]
[/TR]
</tbody>[/TABLE]

The macro takes 80% of JOHNSONOIL and compares with the next cell - so in this case it matches.

That's why I asked if your macro does what you want - it presumably doesn't.
How do you want the comparison done?
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
i think, i am good too go because its just one case. by any which ways we have either compare first row to second row or second to first row. if we follow both the parameters then code will be large and there is maximum possibility then excel gets stuck and stop working
 
Upvote 0
i think, i am good too go because its just one case. by any which ways we have either compare first row to second row or second to first row. if we follow both the parameters then code will be large and there is maximum possibility then excel gets stuck and stop working

It's still not clear to me exactly what the criteria are for coloring the cells.
Following both parameters would not be a problem but don't see what that would achieve - your JOHNNSONOIL example would still get colored.
 
Upvote 0
Could we have 10-15 rows of varied dummy sample data, the expected results and explanation in relation to that sample data?
 
Upvote 0
it will be maximum go till 6-to 7 rows.
[TABLE="width: 156"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]402445477567[/TD]
[TD]8HEALTHSOUTH CENTER PARHOI[/TD]
[/TR]
[TR]
[TD]402445477567[/TD]
[TD]9DIAGNOSTIC HEALTH OF WESTABC[/TD]
[/TR]
[TR]
[TD]402445477567[/TD]
[TD]3DIAGNOSTIC HEALTH MRI OF LLCPOI[/TD]
[/TR]
[TR]
[TD]402445477567[/TD]
[TD]8OUTPATIENT DIAGNOSTIC CENTER OF EHOI[/TD]
[/TR]
[TR]
[TD]402445477567[/TD]
[TD]8HEALTHSOUTH CENTER PARHOI[/TD]
[/TR]
[TR]
[TD]402445477567[/TD]
[TD]8HEALTHSOUTH DIAGNOSTIC CENTER INCHOI[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:
Upvote 0
But what result do you want and why? What about the JOHNNSOIL example?
Should the data be sorted before doing the comparison?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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