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
JOHNSONNOIL
JOHNSONNOILANUNITEDGENERALPARTNERSHIP

<tbody>
</tbody>

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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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.
4024454775678HEALTHSOUTH CENTER PARHOI
4024454775679DIAGNOSTIC HEALTH OF WESTABC
4024454775673DIAGNOSTIC HEALTH MRI OF LLCPOI
4024454775678OUTPATIENT DIAGNOSTIC CENTER OF EHOI
4024454775678HEALTHSOUTH CENTER PARHOI
4024454775678HEALTHSOUTH DIAGNOSTIC CENTER INCHOI

<colgroup><col><col></colgroup><tbody>
</tbody>
 
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,215,273
Messages
6,123,985
Members
449,137
Latest member
abdahsankhan

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