VBA change cell colour based on array

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, I am trying to highlight cells if part of the cell contains a number from an array, once finished looping through add a message box as a warning that the numbers from the array were found, Here is what I have so far but I can't seem to get it to work, Can someone help with this please

Code:
    Dim x As range, MyArr As Variant, i As Long
        MyArr = Array("101923", "114054", "115501", "117889", "122351", "122352", "125448", "125515", "125516", "125517", "126171", "129320", "129321", "129322", "147499", "157207", "159039", "181603", "190266", "198897", "251583", "262097", "300027", "302689", "304359", "341228")
        For i = LBound(MyArr) To UBound(MyArr)
        For Each x In ActiveSheet.UsedRange
            If InStr(1, MyArr(i)) Then x.Interior.ColorIndex = 36
        Next x
    Next i
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try:-
Code:
If InStr[SIZE=3]([B][COLOR=#ff0000]x[/COLOR][/B][/SIZE], MyArr(i)) Then x.Interior.ColorIndex = 36
 
Last edited:
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