Search value in array and color if meats conditions

pupsia

Board Regular
Joined
Dec 2, 2015
Messages
67
Hello all!

I`m trying to write a macro that goes through all cell in AQ column, splits information in every cell into array and if conditions are met, color the cell.

#AQ COLUMN
1 lineEmail Address
2 lineName Surname; Name.Surname@email.com;
3 lineName Surname; Surname@email.com; Surname@email.com
4 lineNameSurname; Name.Surname@email.com
5 lineName.Surname@email.com
6 lineName Surname;
7 lineName Surname
8 lineName.Surname@email.com; Name.Surname@email.com
9 lineName.Surname@email.com;Name.Surname@email.com
10 lineName.Surname@email.com; Name.Surname@email.com;
11 lineSurname@email.com; Name Surname; Surname@email.com
12 lineName.Surname@email..com
13 line
14 lineNameSurname; Name.Surname@email.com
15 lineName.Surname@email.com

<tbody>
</tbody>


The code I`m using is below. No errors pop up. But nothing is colored.

This macro should find some bad cells in the table above.
The lines that should be colored are: 2, 3, 4, 6, 7, 11, 12, 14

Any ideas where I made a mistake? Please help!

Code:
Sub Test_Test_Test_Test_Test()

    Dim r As Range
    Dim h As Integer
    Dim j As Integer
    Dim ar() As String


Set WB = ThisWorkbook.Worksheets("Bulk")


    With WB
        LastRow = .Cells(.Rows.Count, "AQ").End(xlUp).Row
    End With


    Set r = WB.Range("AQ" & LastRow)
    
For h = 2 To LastRow


    If WB.Range("AQ" & h).Value <> "" Then: GoTo home


    ar = Split(WB.Range("AQ" & h).Value, ";")


    If UBound(ar) >= 0 Then
        For j = 0 To UBound(ar)
            If ar(j) Like "*..*" Then WB.Range("AQ" & h).Interior.ColorIndex = 45
            If Not ar(j) Like "*@*" Then WB.Range("AQ" & h).Interior.ColorIndex = 45
            If Not ar(j) Like "*.*" Then WB.Range("AQ" & h).Interior.ColorIndex = 45
        Next
    End If


home:
Next




End Sub



<colgroup><col></colgroup><tbody>
</tbody>
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Untested, try:
Code:
Sub Test()
    
    Dim a() As String
    Dim r   As Range
    Dim LR  As Long
    Dim x   As Long
    
    Const DELIM As String = ";"
    
    Application.ScreenUpdating = False
        
    With Sheets("Bulk")
        If .AutoFilterMode Then .AutoFilterMode = False
        LR = .Cells(.Rows.count, 43).End(xlUp).row
        .Cells(1, 43).Resize(LR).AutoFilter Field:=1, Criteria1:="="
        For Each r In .Cells(1, 43).Resize(LR).SpecialCells(xlCellTypeVisible)
            a = Split(r.Value, DELIM)
            For x = LBound(a) To UBound(a)
                If InStr(a(x), "..") Or InStr(a(x), "@") Or InStr(a(x), ".") Then Rng.Interior.ColorIndex = 45
            Next x
            Erase a
        Next r
        .AutoFilterMode = False
    End With
            
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
JackDanIce, thank you for your response :) Not sure why, but nothing is happening for some reason :confused:

After a while I changed one line and now is seems to work, more or less.

If WB.Range("AQ" & h).Value = "" Then: GoTo home

Thank you for your help!
 
Upvote 0
You do not need that line at all, can you post the code that is working for you?

This line should field column number 43 (AQ) for values that are blank
Rich (BB code):
.Cells(1, 43).Resize(LR).AutoFilter Field:=1, Criteria1:="="

For none blanks, change code to:
Rich (BB code):
.Cells(1, 43).Resize(LR).AutoFilter Field:=1, Criteria1:="<>"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,944
Members
449,480
Latest member
yesitisasport

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