+ Reply to Thread
Results 1 to 14 of 14

Excel sum formula with "*", written in VBA

  1. #1
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Excel sum formula with "*", written in VBA

    I know this is really an excel function. But is there a way to get around the wildcards to write the following as vba code?

    Please Login or Register  to view this content.
    Any help much appreciated.
    Last edited by Max Peacock; 05-19-2011 at 12:11 PM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Excel sum formula with "*", written in VBA

    Hi and welcome to the board

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    I will do it for you this time

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Excel sum formula with "*", written in VBA

    Well, that looks as though that would be a SUMPRODUCT in Excel 2003, but you couldn't use whole column ranges.

    What are you trying to do? Not in a formula, in real life.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Excel sum formula with "*", written in VBA

    I'm trying to recreate the following excel formula as vba code:

    Please Login or Register  to view this content.
    I know this can be done with an if formula in vba, but I was really looking for a way round the * wildcard.

    The formula looks for all entries in column B with value1, all entries in column C with value2 and inputs the corresponding value (for that row) into the cell with this formula.

    I have also seen the above as an array formula, and rather than try to convert the above into an if formula, I wondered if it could still be done with the * (or some vba replacement) satisfying as a "and" statement.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,446

    Re: Excel sum formula with "*", written in VBA

    Still not sure what you want to do. And what wild cards do you mean? The asterisks (*) are multiplying together the conditions.

    Anyway, see if this helps:

    Please Login or Register  to view this content.

    Assuming that cell F1 is selected, they're all ways of putting the same formula in it (F1).

    The last version could actually be placed in any cell.

    Regards

  6. #6
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Excel sum formula with "*", written in VBA

    All of these codes put the formula into the cell. I only wanted the resultant value. So how could I do indentical to your answers, but without the apostrophes.

    I need to do this for a column over 15000 cells long and was looking for a way to cut down on memory while maintaining the original formula.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel sum formula with "*", written in VBA

    The asterisk is an operator, not a wildcard in this case.

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by snb; 05-19-2011 at 11:20 AM.



  8. #8
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Excel sum formula with "*", written in VBA

    That's doing the job alright. Thanks snb.

    I know vba recognises applications like SUMIF, why not SUM with operator * ?

    i.e. what is wrong with my original code?

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel sum formula with "*", written in VBA

    'Only' this....

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Excel sum formula with "*", written in VBA

    Ah, but you see I don't want the formulas in the cells just the values.

    Am I being to fussy?

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Excel sum formula with "*", written in VBA

    No, in that case:

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Excel sum formula with "*", written in VBA

    Perfect.

    Thanks snb.

  13. #13
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Excel sum formula with "*", written in VBA

    ... It didn't like me evaluating ranges did it? (where excel doesn't mind).

  14. #14
    Registered User
    Join Date
    05-18-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    10

    length of column with named range

    1234567890

+ 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