+ Reply to Thread
Results 1 to 24 of 24

VBA sumif How can i indicate range?

  1. #1
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    VBA sumif How can i indicate range?

    Hey Dear community,

    I use this code

    Please Login or Register  to view this content.
    But instead of "MARKET" i need to use range from sheet2 A2:A35 how can i do that?
    Last edited by jeffreybrown; 12-09-2018 at 10:45 AM. Reason: Please use code tags!

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA sumif How can i indicate range?

    Try this code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    Thanks for reply but i get error Type mismatch

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA sumif How can i indicate range?

    Change "Sheet2" to the name of your sheet
    or if its index Sheet2 use
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    i still get same error / I changed sheet2 to "Markets"

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 12-09-2018 at 10:44 AM. Reason: Please use code tags!

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA sumif How can i indicate range?

    I think you should use
    Sheets("Markets") instead of just Markets

    And it is better to upload sample of your file if you still have a problem

  7. #7
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    Still not working :/

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA sumif How can i indicate range?

    Upload sample of your workbook with some of the desired output

  9. #9
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    i have uploaded it from " Manage attachment "
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VBA sumif How can i indicate range?

    What's your criteria for SUMIF?
    Try this ..
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    Criteria is A2:A35 in sheet2

    not working
    Last edited by Akbarov; 11-29-2018 at 02:16 AM.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,564

    Re: VBA sumif How can i indicate range?

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    Thank you very much works.

    But can you explain me? because i need to do same think for B2:B111 too

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,564

    Re: VBA sumif How can i indicate range?

    Change last line to
    Please Login or Register  to view this content.
    So you will see how it calculates.

    SumIf does not work like this.

  15. #15
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    Sorry i am new in VBA, is there any easy way you explain me? how can i put B2:B111 instead of A2:A35?

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,564

    Re: VBA sumif How can i indicate range?

    Do you mean
    Please Login or Register  to view this content.
    Instead of
    Please Login or Register  to view this content.
    ?

  17. #17
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    thank you very much! if possible last question. how can i put to criteria? if match A2:A35 and "M"

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,564

    Re: VBA sumif How can i indicate range?

    Sorry, but I don't understand what you are trying to say.

    If you upload a workbook with your result, it may help...

  19. #19
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    I mean 2 criteria. If Market name match B2:B111 and H:H match "M"

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,564

    Re: VBA sumif How can i indicate range?

    Quote Originally Posted by Akbarov View Post
    Sorry i am new in VBA
    This is more like a Formula question....
    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    Mr. jindon can you please tell me how can i add 1 more criteria to your formula? if E:E ">0" ?

  22. #22
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,564

    Re: VBA sumif How can i indicate range?

    You need to understand the formula

    Now, enter following formula in any cell and confirm with Ctrl + Shift + Enter(Array formula entry)
    =sum(if((isnumber(match(myrg1,market,0)))*(myrg3="M"),myrg2))

    As you see myrg1,market, myrg3 and myrg2 are all named range.
    If you wan to add more condition, 1st create a named range in ColE ("ColE" for example) that has same size of myrg1 and join with *(condition)
    and see if the formula returns correct value
    =sum(if((isnumber(match(myrg1,market,0)))*(myrg3="M")*(cole>0),myrg2))

    otherwise, every time you need to change it , you need to ask.

  23. #23
    Forum Contributor
    Join Date
    06-30-2018
    Location
    Azerbaijan
    MS-Off Ver
    Excel 2016
    Posts
    145

    Re: VBA sumif How can i indicate range?

    shuld i change MyRG each time from name manager? for example MyRg1 refers to O:O on second code it refers to D:D i use same code for 12 results, i change refer adress from VBA code
    Last edited by Akbarov; 12-09-2018 at 09:52 AM.

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,564

    Re: VBA sumif How can i indicate range?

    What are you really trying to do?
    I just used these named range as your original code has them already, though I don't normally use named range.

    If you want that calculation in multiple cells with different column reference, you need to show us in the workbook clearly showing how it should be calculated.

    Otherwise, as I mentioned already, this is rather a forumla question, so better ask in FORMULA section.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Sumif if range does not equal any text in a range
    By Luigi802 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-20-2019, 09:12 AM
  2. [SOLVED] SUMIF formula with dynamic column range and then expand the width of SUM range
    By gravythief in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-26-2017, 08:36 AM
  3. Subtracting from the SUMIF with the difference from the SUMIF range
    By iamblue91 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-04-2014, 09:01 PM
  4. [SOLVED] Shorten SUMIF + SUMIF + SUMIF each with same reference range but different criteria???
    By HeyInKy in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-13-2014, 09:25 PM
  5. [SOLVED] Countif / Sumif Range in a 24 Hour Time Range
    By cwwazy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-16-2013, 04:18 PM
  6. SUMIF Cells in range if values in another range is
    By ChrisNor in forum Excel General
    Replies: 1
    Last Post: 10-08-2009, 11:54 AM
  7. Replies: 2
    Last Post: 01-11-2005, 07:06 PM

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