+ Reply to Thread
Results 1 to 16 of 16

Sum macro

  1. #1
    Registered User
    Join Date
    04-21-2016
    Location
    Boston, England
    MS-Off Ver
    2010
    Posts
    17

    Sum macro

    Hi

    I have a row of cells that I will select and change the colour of the cell and in a hidden row underneath I have values for each cell.

    Is it possible for a macro to calculate the total just by highlighting the cells or by having the cells highlighted and pressing a button to do the calculation.

    If that is possible, how would I go about doing it please?

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Sum macro

    Can you post an example data set that also shows your formatting, and the expected output of the code?
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Sum macro

    Right click on the sheet name at the bottom of excel and select view code

    Paste this code in the macro module that opens and close it.

    Please Login or Register  to view this content.
    The macro will work if you right click on a multiple cell range.

    Right click on a single cell to view the normal right click menu.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    04-21-2016
    Location
    Boston, England
    MS-Off Ver
    2010
    Posts
    17

    Re: Sum macro

    Thanks mehmetcik,

    This is very close to what I am looking for but I would like to highlight the blank cells and it calculate from the hidden cells in the row below and post the result in the blank cells which have been highlighted.

    If this can be done then it would be great!!!

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sum macro

    Maybe:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sum macro

    Maybe:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-21-2016
    Location
    Boston, England
    MS-Off Ver
    2010
    Posts
    17

    Re: Sum macro

    Hi John H Davis,

    I can't get that to work at all I'm afraid.

    Basically if i'm selecting i.e. T6:AL6 I would like it to return the total of the values in T7:AL7 and place it in AL6. The right click function would be great as it is easy to perform for the user.

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sum macro

    Try the Test Sheet. Highlight the cells you want too Sum and let me know if it does what you request with double right click. Row 3 is the target row and Row 4 is hidden.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-21-2016
    Location
    Boston, England
    MS-Off Ver
    2010
    Posts
    17

    Re: Sum macro

    It is nearly there again.

    I need it to add all the values together and place the value in the last box only. It is currency it is adding and it only appears to round numbers off so that is not ideal.

    Many thanks for your help so far.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sum macro

    Try this one. Hope it helps.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    04-21-2016
    Location
    Boston, England
    MS-Off Ver
    2010
    Posts
    17

    Re: Sum macro

    We are nearly there now.

    The only issue I now have is that it is it is not counting the "pence". for instance £15.18 x 4 is £60.72 but it is returning £60.00. Likewise in another row £17.21 x 5 is £86.05 but it is returning £85.00.

    Any help sorting that and I will be extremely grateful.

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sum macro

    Change made - Note Dimmed y as Currency instead of long.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    04-21-2016
    Location
    Boston, England
    MS-Off Ver
    2010
    Posts
    17

    Re: Sum macro

    That is perfect! Thank you.

    One last question.

    If I had a second row of prices underneath how could I combine the two differences depending on colour. If I copy the code and change the offsets and colour ref it has a Ambiguous name conflict. I know I could have double click but I would prefer it to be one simple method determined on colour.

    Any help with this final piece and I will be ecstatic!

  14. #14
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sum macro

    You're welcome. Glad to help out. If you copy the code and paste in a module to avoid the Ambiguous name conflict you need too change the name of the Sub procedure. You can't have two Sub procedures with the same name.

  15. #15
    Registered User
    Join Date
    04-21-2016
    Location
    Boston, England
    MS-Off Ver
    2010
    Posts
    17

    Re: Sum macro

    Hi John H Davis,

    I have tried this but to no avail.

    Any chance you could post an example so I can see where I am going wrong please?


  16. #16
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Sum macro

    You can't have a sub named macro1 twice in your modules. Or any duplicate names for Subs.

    Please Login or Register  to view this content.
    This will produce the Ambiguous Name error.

    You'd have too change it like this or another way.

    Please Login or Register  to view this content.

+ 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] Define variable in macro than calling that macro inside another macro
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2015, 10:58 AM
  2. Using a macro on workbook1 to create a button in wb2 and assigning macro "wb2!macro"
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2014, 11:39 AM
  3. [SOLVED] Macro to show Which macro didnt work in a nested macro
    By akhileshgs in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-10-2013, 03:21 AM
  4. Perform macro "on open" specific file- store macro in Personal Macro Workbook?
    By thompssc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2012, 12:38 PM
  5. lookup macro, solver macro, realtime macro
    By xelhelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2011, 06:14 PM
  6. Cannot find macro error when running a macro from a macro in a diffrent workbook.
    By Acrobatic82 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2010, 09:22 AM
  7. Macro calling another Macro: "The macro 'Personal.xls!FindChar"
    By William Benson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2005, 09:05 AM

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