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.

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
ALMAZROUIMEDICALICALCHEMICALSUPPLIES
ALMAZROUIMEDICALICALCHEMICALSUPPLIES
INTERNATIONALAERADIOEMI
INTERNATIONALAERADIOEMIRATE
GULFDRUG
GULFDRUGESTABLISHMENT

<tbody>
</tbody>

INTERNATIONALAERADIOEMI
INTERNATIONALAERADIOEMIRATE

<tbody>
</tbody>
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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