+ Reply to Thread
Results 1 to 9 of 9

Unable to enter a cell formula that sums a variable using VBA

  1. #1
    Registered User
    Join Date
    05-25-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2010
    Posts
    3

    Unable to enter a cell formula that sums a variable using VBA

    Hi,

    I am trying to sum up a variable range. This range is stored as a string variable called Name. I want the sum to be stored in cell (i,4). The following formula is giving me an error and I can't figure out why:

    Cells(i, 4).Formula = = "=SUM(" & Name & ")"

    My Name variable is also set up correctly (list of cells separated by commas).

    Does anybody have any ideas?

    Sorry if this has already been answered - did a search and nothing came up.

  2. #2
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Unable to enter a cell formula that sums a variable using VBA

    I'm just curious: you typed an extra = by mistake, or do you really have this in your code?
    Last edited by Sbarro79; 05-25-2013 at 07:47 PM.

  3. #3
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Unable to enter a cell formula that sums a variable using VBA

    This sample code works fine:
    Please Login or Register  to view this content.
    Does that give you an clues to what's going wrong in your situation?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  4. #4
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Unable to enter a cell formula that sums a variable using VBA

    Well, you do show two = signs before the quotes, as well as one after.

    If that doesn't solve it tell us exactly what you have for the variable Name.

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    05-25-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Unable to enter a cell formula that sums a variable using VBA

    Oh sorry - there are only two = signs, I copied and pasted wrong..

    For the Name variable, I have "Daily!$B$1,Daily!$B$3", where Daily is the sheet name

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Unable to enter a cell formula that sums a variable using VBA

    So does Name include the quotes, or have you just put them in your post for clarity ?

    What type of error is being reported ?

    Pete

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Unable to enter a cell formula that sums a variable using VBA

    Still no problem using this code:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-25-2013
    Location
    Toronto, ON
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Unable to enter a cell formula that sums a variable using VBA

    Hi,

    Yes, the quotes are included in Name.
    The error that I'm getting is: Run time error 1004 - Application defined or object defined error
    I get that error when I used the same code that Ron is using.

    Thanks for all the help : )

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Unable to enter a cell formula that sums a variable using VBA

    What exactly is in Name?
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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