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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,040
Members
448,543
Latest member
MartinLarkin

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