Excel VBA Insert Formula Into Cell using a variable

Hello Experts,

This should be easy but I can not get the following to work.

I'm entering a formula into a cell using a variable in the formula.  What I need to do is insert a formula that gives the average of C2 to N , where N is an entry the user puts in.  Soooo, the formula that gets posted into F1 is: Range("F1").Formula = "=Average("$C$3" ":" "$C,$N" )"  I am fairly new to Excel VBA.  Thanks!!
LVL 2
CompTech810Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Range("F1").Formula = "=Average("$C$3:$C" & N)
Martin LissOlder than dirtCommented:
BTW you said C2 but your example shows C3, so I went with that.
Saqib Husain, SyedEngineerCommented:
Try

Range("F1").Formula = "=Average($C$3:$C$" & N & ")"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

CompTech810Author Commented:
Thanks for the quick response!

Martin I tried your formula and received an error at the first $, "Invalid Character"

Saqib I tried your formula and this is the result in F1:  =AVERAGE("$C$2:$C$"&n )
Saqib Husain, SyedEngineerCommented:
I have modified my formula. Give it a go again.
CompTech810Author Commented:
Saqib that worked!!  Thanks!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.