ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If-Then in VBA (https://www.excelbanter.com/excel-programming/295215-if-then-vba.html)

Jon Minken

If-Then in VBA
 
I am trying to create a button that will evaluate a cell
and based upon its value, enter one of 2 formulas. after
writing the code, it keeps returning a value that it
should notand I can't figure why.

Here is the Attached code

Sub manual312()
'
' manual312 Macro
' Macro recorded 4/15/2004 by jminken
'
Sheets("Reimbursement Sheet Global").Select

If check312 = 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.2


ElseIf check312 0 Then

Range("R32").Select

ActiveCell.FormulaR1C1 = _
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-21]
C[4]*R[-21]C)"
Range("R34").Select


End If
'
End Sub

The problem arises in that the check312 cell is 0 and I
am getting the first formula.

Please help

Chris

If-Then in VBA
 
try simplifying your code like this
Sub manual312(
Sheets("Reimbursement Sheet Global").Selec
If check312 = 0 The
Range("R32").Selec
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.
Exit Su
End I
Range("R32").Selec
ActiveCell.FormulaR1C1 = "=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-21] C[4]*R[-21]C)
Range("R34").Selec
End Su


----- Jon Minken wrote: ----

I am trying to create a button that will evaluate a cell
and based upon its value, enter one of 2 formulas. after
writing the code, it keeps returning a value that it
should notand I can't figure why

Here is the Attached cod

Sub manual312(

' manual312 Macr
' Macro recorded 4/15/2004 by jminke

Sheets("Reimbursement Sheet Global").Selec

If check312 = 0 The
Range("R32").Selec
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.


ElseIf check312 0 The

Range("R32").Selec

ActiveCell.FormulaR1C1 =
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-21
C[4]*R[-21]C)
Range("R34").Selec


End I

End Su

The problem arises in that the check312 cell is 0 and I
am getting the first formula.

Please hel


Sam

If-Then in VBA
 
Try this.

Sub manual312()

Sheets("Reimbursement Sheet Global").Select
If check312 = 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.2
End
Else
If check312 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = _
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-21]C
[4]*R[-21]C)"
Range("R34").Select
End
End If
End If
End Sub




-----Original Message-----
I am trying to create a button that will evaluate a cell
and based upon its value, enter one of 2 formulas. after
writing the code, it keeps returning a value that it
should notand I can't figure why.

Here is the Attached code

Sub manual312()
'
' manual312 Macro
' Macro recorded 4/15/2004 by jminken
'
Sheets("Reimbursement Sheet Global").Select

If check312 = 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.2


ElseIf check312 0 Then

Range("R32").Select

ActiveCell.FormulaR1C1 = _
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-

21]
C[4]*R[-21]C)"
Range("R34").Select


End If
'
End Sub

The problem arises in that the check312 cell is 0 and I
am getting the first formula.

Please help
.


No Name

If-Then in VBA
 
Thanks but it is not working

Icannot figure out why
-----Original Message-----
Try this.

Sub manual312()

Sheets("Reimbursement Sheet Global").Select
If check312 = 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.2
End
Else
If check312 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = _
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-21]

C
[4]*R[-21]C)"
Range("R34").Select
End
End If
End If
End Sub




-----Original Message-----
I am trying to create a button that will evaluate a cell
and based upon its value, enter one of 2 formulas. after
writing the code, it keeps returning a value that it
should notand I can't figure why.

Here is the Attached code

Sub manual312()
'
' manual312 Macro
' Macro recorded 4/15/2004 by jminken
'
Sheets("Reimbursement Sheet Global").Select

If check312 = 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.2


ElseIf check312 0 Then

Range("R32").Select

ActiveCell.FormulaR1C1 = _
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-

21]
C[4]*R[-21]C)"
Range("R34").Select


End If
'
End Sub

The problem arises in that the check312 cell is 0 and I
am getting the first formula.

Please help
.

.


ryan

If-Then in VBA
 
where do you declare a value for the variable check312

----- wrote: ----

Thanks but it is not workin

Icannot figure out wh
-----Original Message----
Try this
Sub manual312(
Sheets("Reimbursement Sheet Global").Selec

If check312 = 0 The
Range("R32").Selec
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.
En
Els
If check312 0 The
Range("R32").Selec
ActiveCell.FormulaR1C1 =
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-21


[4]*R[-21]C)
Range("R34").Selec
En
End I
End I
End Su
-----Original Message----

I am trying to create a button that will evaluate a cell
and based upon its value, enter one of 2 formulas. after
writing the code, it keeps returning a value that it
should notand I can't figure why
Here is the Attached cod
Sub manual312(


' manual312 Macr
' Macro recorded 4/15/2004 by jminke

Sheets("Reimbursement Sheet Global").Selec
If check312 = 0 The

Range("R32").Selec
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.
ElseIf check312 0 The
Range("R32").Selec
ActiveCell.FormulaR1C1 =

"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[

21
C[4]*R[-21]C)
Range("R34").Selec
End I


End Su
The problem arises in that the check312 cell is 0 and I

am getting the first formula.
Please hel





JWolf

If-Then in VBA
 
Why don't you just enter this formula in R32:

=IF(check312=0,Medicare_payment_312*1.2,IF(check31 20,U7*R7+U9*R9+U11*R11,""))

Sam wrote:
Try this.

Sub manual312()

Sheets("Reimbursement Sheet Global").Select
If check312 = 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.2
End
Else
If check312 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = _
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-21]C
[4]*R[-21]C)"
Range("R34").Select
End
End If
End If
End Sub





-----Original Message-----
I am trying to create a button that will evaluate a cell
and based upon its value, enter one of 2 formulas. after
writing the code, it keeps returning a value that it
should notand I can't figure why.

Here is the Attached code

Sub manual312()
'
' manual312 Macro
' Macro recorded 4/15/2004 by jminken
'
Sheets("Reimbursement Sheet Global").Select

If check312 = 0 Then
Range("R32").Select
ActiveCell.FormulaR1C1 = Medicare_payment_312 * 1.2


ElseIf check312 0 Then

Range("R32").Select

ActiveCell.FormulaR1C1 = _
"=(R[-25]C[4]*R[-25]C)+(R[-23]C[4]*R[-23]C)+(R[-


21]

C[4]*R[-21]C)"
Range("R34").Select


End If
'
End Sub

The problem arises in that the check312 cell is 0 and I
am getting the first formula.

Please help
.



All times are GMT +1. The time now is 09:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com