LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default Programmatically add worksheet function

Thanks for the help. The .Formula tip will be most useful.

"Chip Pearson" wrote:

You can't use a variable directly within the formula string because that is
passed to Excel and Excel has no idea about VBA variable. Your code is very
close to what you want. Try

Worksheets("Sheet2").Range("C1").Value = "=SUM(C2:C" & LastRow & ")"

Also, as a matter of style, I would change .Value to .Formula. Value will
work, but Formula is more accurate and self-explanatory.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




"Office_Novice" wrote in message
...
I haven't tried this before now and i am having a little trouble.

This is what i have:
Worksheets("Sheet2").Range("C1").Value = "=SUM(C2:C5000)"

And it works ok, But i wont always know the range. I need something like:

Worksheets("Sheet2").Range("C1").Value = "=SUM(C2:C" & LastRow)"

But i tried that and the function didnt recognize my variable. Any help
would be great.


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically add a Formula in a worksheet? circuit_breaker Excel Worksheet Functions 3 July 6th 09 02:53 PM
Programmatically selecting first worksheet Barb Reinhardt Excel Programming 1 July 14th 06 12:38 AM
Programmatically selecting first worksheet Barb Reinhardt Excel Programming 4 July 13th 06 11:42 PM
How to add an image to a worksheet programmatically mjohnson Excel Discussion (Misc queries) 2 March 16th 05 04:48 PM
Programmatically Add Worksheet Event The Vision Thing Excel Programming 1 September 2nd 04 02:14 AM


All times are GMT +1. The time now is 01:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"