IF Function as formula not working in VBA

Janb

New Member
Joined
Feb 19, 2009
Messages
39
To get the following formula in a cell (example N1912 but it's always the 3rd row below the lastrow)

Excel Formula:
= if(N1912 > 500, 0, 25)

I'm using the code below. But the result is TRUE instead of 0 when OndergrensOnderwaarde < 500 and 25 when the value >+ 500

OndergrensOnderwaarde = 500.
The value of it is in the .offset(2,13)

VBA Code:
.Offset(3, 13).Formula = "=if(" & .Offset(2, 13).Address >= " & OndergrensOrderwaarde  ,0 , 25)"

I've tried a lot of combinations and did a lot of research on Google but can't figure it out.

Can you please help?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try it like
VBA Code:
.Offset(3, 13).Formula = "=if(" & .Offset(2, 13).Address & ">= OndergrensOrderwaarde  ,0 , 25)"
 
Upvote 0
Try it like
VBA Code:
.Offset(3, 13).Formula = "=if(" & .Offset(2, 13).Address & ">= OndergrensOrderwaarde  ,0 , 25)"

Thank you for your quick answer. I have result but the variable OndergrensWaarde is text instead of a number:

Result:
Excel Formula:
=IF($N$1922>=@ OndergrensOrderwaarde;0; 25)
 
Upvote 0
As there was no mention of it being a variable I assumed it was a named range.
Try
VBA Code:
.Offset(3, 13).Formula = "=if(" & .Offset(2, 13).Address & ">=" & OndergrensOrderwaarde & "  ,0 , 25)"
 
Upvote 0
Solution
As there was no mention of it being a variable I assumed it was a named range.
Try
VBA Code:
.Offset(3, 13).Formula = "=if(" & .Offset(2, 13).Address & ">=" & OndergrensOrderwaarde & "  ,0 , 25)"

Thank you very much! It works.

PS apologize for the variable. I thought that it was clear when I mentioned OndergrensOrderwaarde = 500.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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