+ Reply to Thread
Results 1 to 7 of 7

VBA: Need SUMIF formula where only the first 9 characters match

  1. #1
    Forum Contributor
    Join Date
    03-14-2005
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    172

    VBA: Need SUMIF formula where only the first 9 characters match

    Is there a way to have a sumif formula where only the first X number of characters are matching. Example

    Column A Column B Column C
    1 IS1004790 100
    2 IS1004790 100
    3 IS1004790 100
    4 IS1004790 2 200
    5 IS1004790 3 100
    6 IS1004790 4 100

    My formula in column C is =SUMIF(A:A,A1,B:B), which gives me 300 for rows 1,2,3, but 4 gives me 200 and 5 gives me 100 and 6 gives me 100.

    I want it to sum all 6 rows because I don't care about the last number. Basically total to 700 in each row in column C. I want the first nine characters to match to do the sum, not an exact match to do the sum. Any help?
    edit: attached sample, because formatting above is not so good
    Attached Files Attached Files
    Last edited by Mile029; 06-24-2020 at 11:26 PM. Reason: attached sample

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Need SUMIF formula where only the first 9 characters match

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    03-14-2005
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    172

    Re: Need SUMIF formula where only the first 9 characters match

    Quote Originally Posted by protonLeah View Post
    Please Login or Register  to view this content.
    awesome, works in my spreadsheet, but when I put it in a macro, it doesn't, gives me a VALUE error. is there something I'm missing?

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Need SUMIF formula where only the first 9 characters match

    Quote Originally Posted by Mile029 View Post
    ... but when I put it in a macro, it doesn't...
    Then perhaps you should have specified that it was going into a macro?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Contributor
    Join Date
    03-14-2005
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    172

    Re: Need SUMIF formula where only the first 9 characters match

    Quote Originally Posted by FDibbins View Post
    Then perhaps you should have specified that it was going into a macro?
    Sorry, it's going to be in a macro.

    I've used SUMIF in macros before and they basically work the same.

    This is my line in the macro:
    Const F = "IF({1},ROUND(SUMPRODUCT(--(left(E:E#,9)=left(E#,9)),L:L)),2)=0)"

    basically looking to see if it totals to zero.
    Last edited by Mile029; 06-25-2020 at 12:27 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,807

    Re: VBA: Need SUMIF formula where only the first 9 characters match

    Thread moved to the correct section and title updated.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: VBA: Need SUMIF formula where only the first 9 characters match

    Thanks Ali, I should have done that, too

+ 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] Multiple SUMIF formula based on first few characters of cell...
    By nimv1 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-29-2018, 04:12 AM
  2. [SOLVED] Match & Sumif Formula
    By rizmomin in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-06-2018, 11:51 AM
  3. Sumif + Match Formula?
    By kris9172 in forum Excel General
    Replies: 1
    Last Post: 01-18-2017, 04:09 PM
  4. SumIf if First 10 Characters match cell
    By WaylettChris in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-25-2016, 08:42 AM
  5. return first four characters AFTER index match formula
    By ammartino44 in forum Excel General
    Replies: 2
    Last Post: 07-23-2015, 07:17 PM
  6. [SOLVED] Formula Match First Few Characters in a Text String
    By phelbin in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-23-2015, 11:24 AM
  7. [SOLVED] How do I use wildcard characters in Excel 2003 sumif formula?
    By Erik T in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-13-2006, 04:45 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