Newbie! Help With Multiple If Statement

Aarondo

New Member
Joined
Jul 17, 2010
Messages
24
Hi guys hope you're all well!

This is my first attempt at scripting something in VBA and Im trying to do a formula with multiple if statement

Im basically trying to script something so that when 4 criteria are met it deletes 2 cells. Heres my code


Sub test()

If Range("P9") = Range("H9") And Range("P11") = Range("G9") And Range("T9") = "YES" And Range("T11") = "YES" Then

Range("O9").ClearContents And Range("010").ClearContents

End If

End Sub

Can anyone help. Many thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub test()

If Range("P9") = Range("H9") And Range("P11") = Range("G9") And Range("T9") = "YES" And Range("T11") = "YES" Then

    Range("O9:O10").ClearContents

End If

End Sub
 

Aarondo

New Member
Joined
Jul 17, 2010
Messages
24
Hi, thanks for your reply.

Ive tried that and its still not working, any ideas?

Thanks
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092

ADVERTISEMENT

In what way isn't it working?
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Try:

Code:
Sub test()
    If Range("P9").Value = Range("H9").Value And Range("P11").Value = Range("G9").Value And Range("T9").Value = "YES" And Range("T11").Value = "YES" Then
        Range("O9:O10").ClearContents
    End If
End Sub

If it still doesn't work one or more of your conditions must be False.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,448
Messages
5,642,218
Members
417,262
Latest member
andrewd1

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