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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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:
Upvote 0
Bad syntax. Change this bit:

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

to this:

If D.Interior.Color = vbGreen
 
Upvote 0
Perfect guys thanks.

Peter it is some dirty code I nicked from somewhere else, b isn't needed and I have removed it, thanks.
 
Upvote 0
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. :)
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,121
Members
453,021
Latest member
Justyna P

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