+ Reply to Thread
Results 1 to 16 of 16

For every blank cell , sum those above it

  1. #1
    Registered User
    Join Date
    07-17-2015
    Location
    London
    MS-Off Ver
    10
    Posts
    7

    For every blank cell , sum those above it

    Hi, I wondered if anyone could help with the below
    The spreadsheet below has 3 columns . IN the 3rd there are totals for each group of accounts.
    I need a VBA macro that goes in and finds the blank cell and sums the amounts above that .

    The macro I am using either sums those above completely or sums the 6 above when in some case there are 7 rows to be added.

    A AA 50.00
    A AA 50.00
    A AA 25.00
    A AA 40.00
    A AA 20.00
    A AA 10.00

    B BB 11.00
    B BB 15.00
    B BB 2.00
    B BB 3.00
    B BB 4.00
    B BB 5.00
    B BB 6.00

    C CC 1.50
    C CC 2.60
    C CC 3.60
    C CC 5.00
    C CC 10.00
    C CC 15.00
    C CC 20.00
    C CC 25.00
    C CC 30.00
    C CC 35.00
    C CC 100.00
    C CC 1,000.00


    Macro I am using now (that doesn't work !)

    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = "=SUM(INDIRECT(""R1C""&COLUMN()&"":R""& (ROW()-1)&""C""&COLUMN(),FALSE))"
    Selection.Font.Bold = True

    Thank you very much

  2. #2
    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,464

    Re: For every blank cell , sum those above it

    Why not use a Pivot Table?


    A
    B
    C
    D
    E
    F
    G
    1
    Col A
    Col B
    Col C
    Row Labels
    Sum of Col C
    2
    A
    AA
    50
    A
    3
    A
    AA
    50
    AA
    195
    4
    A
    AA
    25
    A Total
    195
    5
    A
    AA
    40
    B
    6
    A
    AA
    20
    BB
    46
    7
    A
    AA
    10
    B Total
    46
    8
    C
    9
    B
    BB
    11
    CC
    1247.7
    10
    B
    BB
    15
    C Total
    1247.7
    11
    B
    BB
    2
    (blank)
    12
    B
    BB
    3
    (blank)
    13
    B
    BB
    4
    (blank) Total
    14
    B
    BB
    5
    Grand Total
    1488.7
    15
    B
    BB
    6
    16
    17
    C
    CC
    1.5
    18
    C
    CC
    2.6
    19
    C
    CC
    3.6
    20
    C
    CC
    5
    21
    C
    CC
    10
    22
    C
    CC
    15
    23
    C
    CC
    20
    24
    C
    CC
    25
    25
    C
    CC
    30
    26
    C
    CC
    35
    27
    C
    CC
    100
    28
    C
    CC
    1,000.00




    Regards, TMS
    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


  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: For every blank cell , sum those above it

    I would do like this with VBA

    Please Login or Register  to view this content.
    The C28 you must change with a lastrow value + 1, the lastrow must always be a blank one.
    Attached Files Attached Files
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Registered User
    Join Date
    07-17-2015
    Location
    London
    MS-Off Ver
    10
    Posts
    7

    Re: For every blank cell , sum those above it

    Thanks every so much keebellah that works nicely !

    When you say LR can I set LR as follows;

    LR = ActiveSheet.UsedRange.Rows.Count
    so

    For Each rng In Range("C" & r1 & :LR")

    Thankyou also to TMS for the pivot table suggestion , that didn't even figure in my solutions , oops!

  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,464

    Re: For every blank cell , sum those above it

    Better to use
    Please Login or Register  to view this content.
    rather than
    Please Login or Register  to view this content.
    as UsedRange can give you more rows (and columns) than are actually used. This can happen when Rows (and/or Columns) are deleted.

    Regards, TMS

  6. #6
    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,464

    Re: For every blank cell , sum those above it

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: For every blank cell , sum those above it

    TMS's option
    Please Login or Register  to view this content.
    Is the best one
    How ever I would use the C column, that's where the values are.

  8. #8
    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,464

    Re: For every blank cell , sum those above it

    How ever I would use the C column, that's where the values are.
    Shouldn't make a difference given that all the columns are populated in the same rows. If one of the columns had more entries, I'd use that but, in this case, I don't think it is important.

    Regards, TMS

  9. #9
    Registered User
    Join Date
    07-17-2015
    Location
    London
    MS-Off Ver
    10
    Posts
    7

    Re: For every blank cell , sum those above it

    Thanks again TMS for all your help, that works nicely

  10. #10
    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,464

    Re: For every blank cell , sum those above it

    You're welcome. Thanks for the rep.

  11. #11
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: For every blank cell , sum those above it

    Here is another possibility that might work.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    07-17-2015
    Location
    London
    MS-Off Ver
    10
    Posts
    7

    Talking Re: For every blank cell , sum those above it

    I have a very similar query and wondered if I could use this thread again?

    The spreadsheet looks like so;

    ABC Amount Apples Pears
    Apples 20 20
    Pears 30 30

    Bass
    Apples 50 50
    Pears 60 60
    A Apples 20 20
    A Pears 30 30
    B Apples 15 15
    B Pears 5 5



    Charlies
    Apples 5 5
    Pears 15 15
    A Apples 20 20
    B Pears 50 50



    I want columns and 4 to have totals included , however I cannot look for blanks as there are formulas in Coulmns C and D as follows;

    =IF(ISNUMBER(SEARCH("apples",A2)),B2,"")

    =IF(ISNUMBER(SEARCH("Pears",A3)),B3,"")

    So basically the macro would put sums after every end of Company ;

    ABC Amount Apples Pears
    Apples 20 20
    Pears 30 30
    20 30
    Bass
    Apples 50 50
    Pears 60 60
    A Apples 20 20
    A Pears 30 30
    B Apples 15 15
    B Pears 5 5

    85 95
    Charlies
    Apples 5 5
    Pears 15 15
    A Apples 20 20
    B Pears 50 50

    25 65

    Thanks lots .... again

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: For every blank cell , sum those above it

    I'll try with what you've posted but I suggest you attach the file, it will make it easier than rewiting the formulas because my country settings are ; instead of , as seprator

  14. #14
    Registered User
    Join Date
    07-17-2015
    Location
    London
    MS-Off Ver
    10
    Posts
    7

    Re: For every blank cell , sum those above it

    Quote Originally Posted by Keebellah View Post
    I'll try with what you've posted but I suggest you attach the file, it will make it easier than rewiting the formulas because my country settings are ; instead of , as seprator
    Thanks Keebellah , sorry for the dealy in responding got caught up in something else !
    Here is the file
    Attached Files Attached Files

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: For every blank cell , sum those above it

    Okay, got the file.
    Will take a look later today

  16. #16
    Registered User
    Join Date
    07-17-2015
    Location
    London
    MS-Off Ver
    10
    Posts
    7

    Re: For every blank cell , sum those above it

    Thanks again

+ 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] Populate Text in Cell based on blank/non-blank status of other cell(s)
    By cmkarnes in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-24-2015, 06:53 AM
  2. Calculate differnce between 2 dates, but if 1 date cell is blank leave cell blank
    By Vicious00013 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-11-2014, 11:31 PM
  3. [SOLVED] Concatenate If Blank - remove blank line if first cell is blank
    By ker9 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-27-2014, 02:14 PM
  4. Replies: 3
    Last Post: 01-23-2014, 12:19 PM
  5. [SOLVED] Cell referenced in formula has no information displayed (shows blank), return blank cell
    By nunayobinezz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-07-2013, 04:51 PM
  6. If cell blank OR another cell blank then show blank, if not display value
    By stevop622 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-09-2013, 04:07 AM
  7. [SOLVED] 1 or blank cell pulls exact text or leaves cell blank
    By sharpmel in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-30-2012, 12:20 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