color cells if two conditions met with vba

youngbella

New Member
Joined
Sep 27, 2020
Messages
19
Office Version
  1. 2010
Platform
  1. Windows
Hi, basically I have this table range.

I want to color the cells that are "0" but have length and serial number. but do nothing if don't have both conditions.

i tried but it turns out all cells with "0" is colored even the conditions not met.

I'm new with VBA. Still trying. glad if you could help.

View attachment 23426

VBA Code:
Sub findzeroandcolor()

Dim findme As Range

For Each findme In Range("A:I")
    If (findme = "0") And (findme.Offset(, -1) <> "") Then
    findme.Interior.ColorIndex = 6
    
    End If
    
Next findme
    
    
End Sub
 

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.
how many cells are to be coloured when a match is found
- only the cell?
- the whole row?
which column contains cells to test for value = 0?
which column contains cells to test for serial number?
which column contains cells to test for length?
 
Upvote 0
how many cells are to be coloured when a match is found
- only the cell?
- the whole row?
which column contains cells to test for value = 0?
which column contains cells to test for serial number?
which column contains cells to test for length?
hi, Yongle.

I have upload the picture
colorthezero.PNG
here.
 
Upvote 0
Try this
VBA Code:
Sub ColourZero()
    Dim cel As Range, test As String, c As Long
    For Each cel In ActiveSheet.Range("A1").CurrentRegion.Resize(, 1)
        For c = 2 To 8 Step 3
            With cel.Offset(, c)
                test = .Offset(, -2) & "|" & .Offset(, -1) & "|" & .Text
                If test = "||0" Then .Interior.Color = vbBlue Else .Interior.Color = xlNone
            End With
        Next c
    Next cel
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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