VBA IF statement with And / Or?

EssKayKay

Board Regular
Joined
Jan 5, 2003
Messages
233
Office Version
  1. 2007
Platform
  1. Windows
I’m looking to cleanup some code.
I believe the following statement can be reduced –

From: If Range(“F2”) > 0 And Range(“F3”) > 0 And Range(“F4”) > 0 Then. . .
To: If Range(“F2,F3,F4”) > 0 Then. . .

Is there such a concatenation for an OR statement such as –
If Range(“F5”) > 0 Or Range(“F6”) > 0 Or Range(“F7”) > 0 Then. . .

Thanks,
Steve
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
To: If Range(“F2,F3,F4”) > 0 Then. . .
Are you sure this statement will work? I think it will only test the first cell regardless of the content of the second and third.
 
Upvote 0
Are you sure this statement will work? I think it will only test the first cell regardless of the content of the second and third.
Excellent, thank you very much Rollis. You are correct, it only checks the first cell. I'm glad I asked.

Again, much appreciated. . .
SKK
 
Upvote 0
@EssKayKay
I have removed the solution mark from post 2 as it is not a solution to your question
Is there such a concatenation for an OR statement such as

You could try these replacement lines
Rich (BB code):
If Range("F2") > 0 And Range("F3") > 0 And Range("F4") > 0 Then ...
If Application.Min(Range("F2:F4")) > 0 Then ...

If Range("F2") > 0 Or Range("F3") > 0 Or Range("F4") > 0 Then ...
If Application.Max(Range("F2:F4")) > 0 Then ...
 
Upvote 0
@EssKayKay
I have removed the solution mark from post 2 as it is not a solution to your question


You could try these replacement lines
Rich (BB code):
If Range("F2") > 0 And Range("F3") > 0 And Range("F4") > 0 Then ...
If Application.Min(Range("F2:F4")) > 0 Then ...

If Range("F2") > 0 Or Range("F3") > 0 Or Range("F4") > 0 Then ...
If Application.Max(Range("F2:F4")) > 0 Then ...
Thank Peter.
So what about cells that are not consecutive - like F2, F3, F8, K9, K12, etc.?
 
Upvote 0
I believe that you would just substitute in
VBA Code:
Range("F2","F3","K9","K12")
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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