condition in an if statement

white_flag

Active Member
Joined
Mar 17, 2010
Messages
331
Hello

I like to add some condition in an if statement:

Code:
if (range("D4").value + 2* range("D5").value)/1000 <= 0.075 then
Range("G10").Formula = "=I4*(I8^4-I9^4)*I7*I5*D6"
else ..etc

without having errors
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
What conditions do you want to add and what's stopping you?

Perhaps this will help - I think you probably need to check out the bits in red:-

How to code IF statements

1) Simple IF with a single statement
Code:
   If condition Then x = 1
2) Simple IF with multiple statements
Code:
   If condition Then x = 1: a = ""
3) Block IF..THEN
Code:
   If condition Then
     x = 1
     a = "xxx"
   End If
4) Block IF..THEN..ELSE
Code:
   If condition Then
     x = 1
     a = "xxx"
   Else
     x = 2
     a = "yyy"
   End If
5) Block IF..THEN..ELSEIF
Code:
   If condition1 Then
     x = 1
     a = "xxx"
   ElseIf condition2 Then
     x = 2
     a = "yyy"
   End If
6) Block IF..THEN..ELSEIF..ELSE
Code:
[COLOR=red]  If condition1 Then[/COLOR]
[COLOR=red]    x = 1[/COLOR]
[COLOR=red]    a = "xxx"[/COLOR]
[COLOR=red]  ElseIf condition2 Then[/COLOR]
[COLOR=red]    x = 2[/COLOR]
[COLOR=red]    a = "yyy"[/COLOR]
[COLOR=red]  ElseIf condition3 Then[/COLOR]
[COLOR=red]    x = 3[/COLOR]
[COLOR=red]    a = "zzz"[/COLOR]
[COLOR=red]  Else[/COLOR]
[COLOR=red]    x = 4[/COLOR]
[COLOR=red]    a = "xyz"[/COLOR]
[COLOR=red]  End If[/COLOR]

How to code SELECT statements

1) Single test variable
Code:
[COLOR=red]  Select Case variable[/COLOR]
[COLOR=red]    Case 1, 3, 6 To 9[/COLOR]
[COLOR=red]      x = 1[/COLOR]
[COLOR=red]      a = "xxx"[/COLOR]
[COLOR=red]    Case Is <= 100[/COLOR]
[COLOR=red]      x = 2[/COLOR]
[COLOR=red]      a = "yyy"[/COLOR]
[COLOR=red]    Case Is <= 1000[/COLOR]
[COLOR=red]      x = 3[/COLOR]
[COLOR=red]      a = "zzz"[/COLOR]
[COLOR=red]    Case Else[/COLOR]
[COLOR=red]      x = 4[/COLOR]
[COLOR=red]      a = "xyz"[/COLOR]
[COLOR=red]  End Select[/COLOR]
2) Multiple test variables
Code:
[COLOR=red]  Select Case True[/COLOR]
[COLOR=red]    Case x < 100[/COLOR]
[COLOR=red]      a = "xxx"[/COLOR]
[COLOR=red]    Case a = "yyy", a = "zzz"[/COLOR]
[COLOR=red]      x = 2[/COLOR]
[COLOR=red]    Case Else[/COLOR]
[COLOR=red]      x = 4[/COLOR]
[COLOR=red]      a = "xyz"[/COLOR]
[COLOR=red]  End Select[/COLOR]
 
Upvote 0
but in my case the condition is an formula from excel and I do not know how to putted in VBA

Code:
if formula.excel <= 1500 then
Range("G10").Formula = "=1500*I4*(I8^4-I9^4)*I7*I5*D6"
else if formula.excel > 1500 then
Range("G10").Formula = "=pi()*I4*(I8^4-I9^4)*I7*I5*D6"
end if
 
Upvote 0
In VBA that would be:-
Code:
(Range("D4").Value+2*Range("D8").Value)/1000
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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