If Then

T

Tom Hutchins

To enter this manually, enter this in F2:

=IF(A2=1,B2*12*0.67,0)

You didn't say what F2 should contain if A2 is not 1, so I just put 0.

To do this using VBA:

If Range("A2").Value = 1 Then
Range("F2").Formula = "=B2*12*.67"
End If

The above code could be part of a VBA procedure.

Hope this helps,

Hutch
 
P

Paul

If you mean put this formula in F2 with VBA given a value of 1 in A2.


Sub EnterValueInF2()

If Range("A2").value=1 then
Range("F2").Formula= "=B2*12*0.67"
End if
End Sub

Paul
 
J

Jamesbfagan

That was really helpful thank you.

If I want it to be able to read multiple values such as if A2 =1 then
F2=B2*12*0.67 or if A2= 2 then F2=B2*12 or if A2=3 then F2=750 how would I do
that?

Thanks Again
 
T

Tom Hutchins

To enter a formula in F2 manually, you can nest up to 7 IF statements (in
Excel 2003 & earlier) like this:

=IF(A2=1,B2*12*0.67,IF(A2=2,B2*12,IF(A2=3,750,0)))

To populate F2 using VBA, you could use something like:

Sub Populate_F2()
Select Case Range("A2").Value
Case 1
Range("F2").Formula = "=B2*12*.67"
Case 2
Range("F2").Formula = "=B2*12"
Case 3
Range("F2").Formula = "=750"
Case Else
'do nothing
End Select
End Sub

Hutch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help 1
Mail Merge Problem 1
Sumproduct Problem 4
Shorten multiple sumifs 3
CONCATENATE code 2
Naming non-contigent cells with vba 5
Excel - Wich Function should I use? 1
Delete rows takes forever 4

Top