VBA IF THEN with 2 conditions

dannyh

Board Regular
Joined
Oct 15, 2007
Messages
156
Hi All

I have this piece of code that is giving me a Runtime error 424

I need it to check every cell in V and every green cell with value 0 it need it to remove its colour, can anyone tell me why I am getting the error.

Code:
    Dim b As Long
    Dim i as Long
    Dim D As Range
    
    b = 2
    For Each D In Range("V2:V" & i - 1)
    If D.Value = Value.Interior.Color = vbGreen And D.Value = "0" Then 'error occurs here
       D.Interior.Color = xlNone
       b = b + 1
    End If
    Next D
Thanks Dan
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,918
Office Version
365
Platform
Windows
Is this what you are trying to do?

Code:
If D.Interior.Color = vbGreen And D.Value = "0" Then
Also, your code shown does not set a value for i
That will also cause an error if you haven't done that.

What is 'b' supposed to be doing in that loop. It is increasing, but not used anywhere.
Should it be
Code:
For Each D In Range("V2:V" & [COLOR="#0000FF"][B]b[/B][/COLOR] - 1)
 
Last edited:

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,059
Office Version
365, 2010
Platform
Windows
Bad syntax. Change this bit:

If D.Value = Value.Interior.Color = vbGreen

to this:

If D.Interior.Color = vbGreen
 

dannyh

Board Regular
Joined
Oct 15, 2007
Messages
156
Perfect guys thanks.

Peter it is some dirty code I nicked from somewhere else, b isn't needed and I have removed it, thanks.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,918
Office Version
365
Platform
Windows
Perfect guys thanks.

Peter it is some dirty code I nicked from somewhere else, b isn't needed and I have removed it, thanks.
You're welcome.
Hopefully you did something about setting 'i' then. :)
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,930
Messages
5,508,184
Members
408,669
Latest member
AgsikapAko

This Week's Hot Topics

Top