Color code if 80% length has same string else yellow color

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
157
Hi Can some one help me with the code that if 80% Length matched then give green color else yellow color.

i have written below code however it is doing green color if 80% length has same string
e.g.

[TABLE="width: 216"]
<tbody>[TR]
[TD]GULFDRUGGU (Length 8)
GULFDRUGGULFDRUGESTABLISHMENT (Lenghth 21)

so it should through yellow color
Code:
Dim rng As Range, cel As RangeWith Worksheets("Grouping Data_Underwriters")
    Set rng = .Range([F2], .Range("F" & Rows.Count).End(xlUp))
End With
For Each cel In rng
    If Left(cel, Len(cel) * 0.8) = Left(cel(2), Len(Left(cel, Len(cel) * 0.8))) Then _
    cel.Resize(2).Interior.Color = vbGreen
    
Next
Name[/TD]
[/TR]
[TR]
[TD]ALMAZROUIMEDICALICALCHEMICALSUPPLIES[/TD]
[/TR]
[TR]
[TD]ALMAZROUIMEDICALICALCHEMICALSUPPLIES[/TD]
[/TR]
[TR]
[TD]INTERNATIONALAERADIOEMI[/TD]
[/TR]
[TR]
[TD]INTERNATIONALAERADIOEMIRATE[/TD]
[/TR]
[TR]
[TD]GULFDRUG[/TD]
[/TR]
[TR]
[TD]GULFDRUGESTABLISHMENT[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 216"]
<tbody>[TR]
[TD]INTERNATIONALAERADIOEMI[/TD]
[/TR]
[TR]
[TD]INTERNATIONALAERADIOEMIRATE[/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I'm not 100% sure what you are asking, but based upon the code you provided, I assume you just need an if/then/else statement

Code:
    If Left(cel, Len(cel) * 0.8) = Left(cel(2), Len(Left(cel, Len(cel) * 0.8))) Then
         cel.Resize(2).Interior.Color = vbGreen
    Else
        cel.Resize(2).Interior.Color = vbYellow
    End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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