VBA Formula Help

Jameo

Active Member
Joined
Apr 14, 2011
Messages
270
Hi guys,

I am trying to get VBA to enter a formula into my sheet. The VBA code is as follows:

Code:
Range("E4").Select
    ActiveCell.FormulaR1C1 = _
        "=INDEX((OFFSET(AvSort!A1,0,0,COUNT(AvSort!i:i),1)),D4,1)"

However, when the macro is ran, the code that gets inserted is:


Code:
=INDEX((OFFSET(AvSort!'A1',0,0,COUNT(AvSort!i:i),1)),'D4',1)

How do I get VBA to enter the code with the ' ' around A1 and D4, as with these symbols, the formula returns an error.

Many thanks for your help
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Code:
[FONT=Arial][SIZE=2][COLOR=#000000]Range("E4").Formula =[/COLOR][/SIZE][/FONT] "=index((offset(avsort!A!,0,0,COUNT(AvSort!I:I),1)),D4,1)"
<table width="64" border="0" cellpadding="0" cellspacing="0"><tbody><tr height="17"><td style="height:12.75pt;width:48pt" width="64" height="17">
</td></tr></tbody></table>
 
Upvote 0
Code:
[FONT=Arial][SIZE=2][COLOR=#000000]Range("E4").Formula =[/COLOR][/SIZE][/FONT] "=index((offset(avsort!A!,0,0,COUNT(AvSort!I:I),1)),D4,1)"
<TABLE cellSpacing=0 cellPadding=0 width=64 border=0><TBODY><TR height=17><TD style="WIDTH: 48pt; HEIGHT: 12.75pt" width=64 height=17>

</TD></TR></TBODY></TABLE>

Brilliant.

Thanks guys :)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,726
Members
452,939
Latest member
WCrawford

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