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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
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?
 

youngbella

New Member
Joined
Sep 27, 2020
Messages
19
Office Version
  1. 2010
Platform
  1. Windows
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.
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,148,391
Messages
5,746,435
Members
424,017
Latest member
jaka

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
Top