Formula with relative references without selecting cell

elnds

New Member
Joined
Dec 5, 2008
Messages
14
Hi,

I'm trying to use VBA to put a formula in a cell which will average the values in the last 6 columns. The following works OK:

TableSheet.Cells(WorkingRow, LastColumn + 1).Select
ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-6]:RC[-1])"

(WorkingRow and LastColumn are integers) but I'd like to avoid selecting the target cell. If I try the following:

TableSheet.Cells(WorkingRow, LastColumn + 1).FormulaR1C1 = "=AVERAGE(RC[-6]:RC[-1]"

nothing is inserted in the target cell (I'm guessing because the relative references refer to the currently selected cell?)

Any suggestions gratefully recieved - thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,

The error is due to the fact that a closing comma is missing from your formula.
Try:
TableSheet.Cells(WorkingRow, LastColumn + 1).FormulaR1C1 = "=AVERAGE(RC[-6]:RC[-1])"
 
Upvote 0
Glad you found solution..

FYI, I'd have to guess that you had an On Error Resume Next type of statement in there.
That was hiding the error you should have been seeing when entering the formula with the missing )
That's why you said it simply didn't enter the formula, instead of "I get an error"..


When troubleshooting, it's a good idea to remove those error handling lines.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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