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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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