+ Reply to Thread
Results 1 to 7 of 7

How to programmatically (VBA macro) set the contents of a cell to be a formula ?

  1. #1
    Registered User
    Join Date
    11-05-2012
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    13

    How to programmatically (VBA macro) set the contents of a cell to be a formula ?

    How would I programmatically (within a VBA macro) set the contents of a cell to be a formula ?

    For example, I know I can set a cell to the contents of a string, by doing

    Please Login or Register  to view this content.
    I tried something like

    Please Login or Register  to view this content.
    but that of course didn't work.

    The formula

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    works for me, but I want to be able to programmatically place it in a cell, while incrementing the cell references in the formula ... IE: E11, F11 .... E12, F12, .... E13, F13 .......

    Thanks
    Last edited by jeffreybrown; 12-10-2012 at 10:24 AM. Reason: Please use code tags...Thanks.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to programmatically (VBA macro) set the contents of a cell to be a formula ?

    example for A11:A19
    Please Login or Register  to view this content.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,232

    Re: How to programmatically (VBA macro) set the contents of a cell to be a formula ?

    Is this what you want?
    http://msdn.microsoft.com/en-us/libr.../ff838835.aspx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    11-05-2012
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: How to programmatically (VBA macro) set the contents of a cell to be a formula ?

    I tried the watersev suggestion and that does almost what I want.

    I have this function below - that works - except of course for adding the formulas.


    Please Login or Register  to view this content.

    Thanks

  5. #5
    Forum Contributor jimmalk's Avatar
    Join Date
    08-31-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: How to programmatically (VBA macro) set the contents of a cell to be a formula ?

    Hi Rex. I recently had a similar issue about programatically putting formulas into ranges. I may be giving you an incorrect suggestion, but 2 points I found was that the cell recieving the formula sometimes (seemingly somtimes, not always) must be set to the General cell format. Also, tag on ".formula" to the code. IE.
    Please Login or Register  to view this content.
    I fixed your qoutes a little also, you had some errors there. Don't know if this fixes your problem for sure. Maybe?

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: How to programmatically (VBA macro) set the contents of a cell to be a formula ?

    @rex99

    Put this instead of commented block in the posted code of yours

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-05-2012
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: How to programmatically (VBA macro) set the contents of a cell to be a formula ?

    That worked - thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1