+ Reply to Thread
Results 1 to 11 of 11

Using variables in SumIf

  1. #1
    Registered User
    Join Date
    12-06-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Using variables in SumIf

    I am trying to put a SUMIF statementin VBA into a moving range of cells as the program cycles through. Therefor I need the criteria of the SUMIF formula to change as well. I want to put variables in for the range in the formula so as the variable lastRow increments, the range the formula searches also increments with that. Any suggestions?

    ie
    Please Login or Register  to view this content.
    Last edited by ngoellner; 12-06-2010 at 01:56 PM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Using variables in SumIf

    Sounds like SUMIFS might be what you are after.

    Can you post a sample of your code so far, or a workbook that demonstrates your problem?

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

    Re: Using variables in SumIf

    Try making all the inner quotes equal double quotes like:
    Please Login or Register  to view this content.
    hth
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    12-06-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Using variables in SumIf

    Here is the piece that has the sum if and the variable used. The rest of the macro is long and proprietary so I can't post it.
    I am going by the logic of the sumif formula of sumif(range to be searched, seach for this, sum this range)

    Please Login or Register  to view this content.
    This way as the variables for lastrow and openrow increase, the formula will move down the sheet and the criteria range will expand.
    Last edited by NBVC; 12-06-2010 at 12:55 PM.

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

    Re: Using variables in SumIf

    Does:
    Please Login or Register  to view this content.
    work?

  6. #6
    Registered User
    Join Date
    12-06-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Using variables in SumIf

    No. I still get the Run-time error '1004':
    Application-defined or object-defined error.

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Using variables in SumIf

    ngoellner,

    Please use code tags around your code snippets... I have corrected them so far.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

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

    Re: Using variables in SumIf

    Try:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-06-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Using variables in SumIf

    sorry about the code snippets. will do.

    and the .value did not change anything.

  10. #10
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Using variables in SumIf

    Maybe this at a guess
    Please Login or Register  to view this content.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  11. #11
    Registered User
    Join Date
    12-06-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Using variables in SumIf

    I figured out the problem. When setting the variables
    Please Login or Register  to view this content.
    It needed the .address extention
    Please Login or Register  to view this content.
    It was picking up the value of the cells and making an incorrect range rather than getting the location of that cell to complete the second half of the range.

    Thanks for the help and the quick responses
    Last edited by ngoellner; 12-06-2010 at 04:05 PM. Reason: Adding 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