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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
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

stephen antoine

Board Regular
Joined
Jun 4, 2008
Messages
128
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

stephen antoine

Board Regular
Joined
Jun 4, 2008
Messages
128
No, Jonmo1 got it...I was trying to offset rows when I actually needed columns...

Thanks for your reply...
 
Upvote 0

Forum statistics

Threads
1,191,123
Messages
5,984,774
Members
439,910
Latest member
Flyingjoblo

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
Top