Hi,
I've recorded a macro to do a simply subtraction of two cells (Column E - Column F). I used the option for "relative references" when recording the macro, and this works correctly for the following rows.
The problem I have is that I need to execute this macro in a number of possible columns, however the macro seem to record the "distance" from the columns where it should perform the subtraction. As a result it won't work when it try and execute in a different column to the one where it originally recorded the macro.
How can I change the macro so that performs the subtraction for columns E and F, regardless of which column I execute the macro in?
Current macro code is as follows:
Thank you for your help.Sub Calculate_NET_price() ' ' Keyboard Shortcut: Ctrl+Shift+G ' ActiveCell.Select ActiveCell.FormulaR1C1 = "=RC[-9]-RC[-8]" ActiveCell.Offset(1, 0).Range("A1").Select End Sub
Steve.
You need to use Absolute reference for the columns, not the rows. For columns E and F
Notice the [ ] - this is a relative reference - omit these for absolute referencesActiveCell.FormulaR1C1 = "=RC6-RC5"
See this link http://office.microsoft.com/en-us/he...005198323.aspx
Last edited by smuzoen; 02-04-2012 at 09:58 PM.
Hope this helps.
Anthony
Pack my box with five dozen liquor jugs
PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated”
Thanks a lot!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks