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.

[TABLE="width: 500"]
<tbody>[TR]
[TD]#[/TD]
[TD]AQ COLUMN[/TD]
[/TR]
[TR]
[TD]1 line[/TD]
[TD]Email Address[/TD]
[/TR]
[TR]
[TD]2 line[/TD]
[TD]Name Surname; Name.Surname@email.com;[/TD]
[/TR]
[TR]
[TD]3 line[/TD]
[TD]Name Surname; Surname@email.com; Surname@email.com[/TD]
[/TR]
[TR]
[TD]4 line[/TD]
[TD]NameSurname; Name.Surname@email.com[/TD]
[/TR]
[TR]
[TD]5 line[/TD]
[TD]Name.Surname@email.com[/TD]
[/TR]
[TR]
[TD]6 line[/TD]
[TD]Name Surname; [/TD]
[/TR]
[TR]
[TD]7 line[/TD]
[TD]Name Surname[/TD]
[/TR]
[TR]
[TD]8 line[/TD]
[TD]Name.Surname@email.com; Name.Surname@email.com[/TD]
[/TR]
[TR]
[TD]9 line[/TD]
[TD]Name.Surname@email.com;Name.Surname@email.com[/TD]
[/TR]
[TR]
[TD]10 line[/TD]
[TD]Name.Surname@email.com; Name.Surname@email.com;[/TD]
[/TR]
[TR]
[TD]11 line[/TD]
[TD]Surname@email.com; Name Surname; Surname@email.com[/TD]
[/TR]
[TR]
[TD]12 line[/TD]
[TD]Name.Surname@email..com[/TD]
[/TR]
[TR]
[TD]13 line[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]14 line[/TD]
[TD]NameSurname; Name.Surname@email.com[/TD]
[/TR]
[TR]
[TD]15 line[/TD]
[TD]Name.Surname@email.com[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 474"]
<colgroup><col></colgroup><tbody>[TR]
[TD]
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


[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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,224,975
Messages
6,182,112
Members
453,089
Latest member
boonga

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