Formula in macro not working

stephen antoine

Board Regular
Joined
Jun 4, 2008
Messages
128
Can someone please let me know what is wrong with the following?

Code:
ActiveCell.Formula = "=" & ActiveCell.Offset(-2, 0).Address(0,0) & "-" & ActiveCell.Offset(-1, 0).Address(0,0)

I can't figure out why I'm getting an error

Thanks
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
It would error if your current ActiveCell is in Row 1 or 2, since ActiveCell.Offset(-2,0) would try to go to row 0 or -1...

Other than that, it works fine for me..
 
Upvote 0
Stephen

What's the active cell when the code runs?

If it's anything in row 1 or 2 then the code will error.

Perhaps you should post the rest of the code and explain what it's purpose is.:)
 
Upvote 0
OMG I'm an idiot!!!

Thanks, I was racking my brain on this yesterday. I guess I was just fried or something....

Thanks again
 
Upvote 0

Forum statistics

Threads
1,215,042
Messages
6,122,810
Members
449,095
Latest member
m_smith_solihull

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