VBA hard code formula problems

wigarth

Board Regular
Joined
Apr 16, 2016
Messages
51
Office Version
  1. 365
Platform
  1. Windows
Hi!

I have a big workbook that evolves around a cell (O3)
In this case O3=11, but this number/cell changes several times during a working day.

When running the macro, I need the vba to hardcode a formula to A2 with a number from cell O3

The working formula is:
Excel Formula:
=IF(sheet1!B11=0,0,sheet1!B11)   <-- where 11 is the value from the cell O3

In vba i tried this:
VBA Code:
Range("A2").Formula = "=IF(Sheet1!B" & [O3].Value & "=0,0,Sheet1!B" & [O3].Value & ")"

However this is not working...
I get it to work up to the point where i start addig the "IF" statement, but after that everything creates "Object missing" message

Anyone that can crack this?

Best reggards:
Wigarth
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hello Wigarth

Kindly try the following code

VBA Code:
ActiveSheet.Range("A2").Formula = "=IF(Sheet1!B" & Range("O3").Value & "=0,0,Sheet1!B" & Range("O3").Value & ")"
 
Upvote 0
Hello Wigarth

Kindly try the following code

VBA Code:
ActiveSheet.Range("A2").Formula = "=IF(Sheet1!B" & Range("O3").Value & "=0,0,Sheet1!B" & Range("O3").Value & ")"
Excellent!!! Thank You so Much Haree. worked like a charm!
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,892
Members
449,194
Latest member
JayEggleton

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