#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default If Then

How would I program the following formula?

If A2=1 Then F2=B2*12*.67
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default If Then

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

"Jamesbfagan" wrote:

How would I program the following formula?

If A2=1 Then F2=B2*12*.67

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default If Then

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


"Jamesbfagan" wrote in message
...
How would I program the following formula?

If A2=1 Then F2=B2*12*.67



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default If Then

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

"Tom Hutchins" wrote:

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

"Jamesbfagan" wrote:

How would I program the following formula?

If A2=1 Then F2=B2*12*.67

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default If Then

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

"Jamesbfagan" wrote:

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

"Tom Hutchins" wrote:

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

"Jamesbfagan" wrote:

How would I program the following formula?

If A2=1 Then F2=B2*12*.67

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"