+ Reply to Thread
Results 1 to 15 of 15

Macro to Autosum variable rows above selected cell

  1. #1
    Registered User
    Join Date
    11-24-2012
    Location
    Stratford-upon-Avon
    MS-Off Ver
    Excel 2007
    Posts
    89

    Macro to Autosum variable rows above selected cell

    Hope somebody can help please. I need a Macro to autosum from a selected row cell in column D and perform autosum in all rows above it until it reaches the last autosum row. I need this to work from column D to AB.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to Autosum variable rows above selected cell

    Hello Stratfordoaks,

    Welcome to the Forum.

    Check if the attached WorkBook is what you have in mind.

    Also see the "Please consider" note at the bottom of this Post.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Autosum variable rows above selected cell

    Hi, Winon,

    I´m not so sure about the AutoSum range being a determined range but TO may clear that.

    I would have taken a Loop instead of writing all the formulas:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to Autosum variable rows above selected cell

    @ HaHoBe,

    Hello "Ciao",

    I couldn't agree with you more Holger.

    The only thing is that I am not sure as to what level of VBA skills the OP has to understand what Dims, Constants and Loops are.

    So I kept it simple basic "Longhand".

  5. #5
    Registered User
    Join Date
    11-24-2012
    Location
    Stratford-upon-Avon
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Macro to Autosum variable rows above selected cell

    Hi Winon

    Thanks for your reply. I forgot to mention that I need this macro to start in the active cell which could be any row in column D and then run macro to sum above to the last row containing an autosum or this could be a blank line. I have linked my worksheet to show you.

    Worksheet

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Macro to Autosum variable rows above selected cell

    Hello Stratfordoaks,

    The file download was reported as unsafe, containing viruses, etc. So I had to abort the Download. Please could you upload your Workbook via the Forum Posts by Clicking on Go Advanced, and upload from there.

    Thank you.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Autosum variable rows above selected cell

    Hi, Stratfordoaks,

    if you offer a workbook for download I would get rid of every link to another workbook on your Desktop.

    Give this a try:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    11-24-2012
    Location
    Stratford-upon-Avon
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Macro to Autosum variable rows above selected cell

    Hi Winon

    Ok here it is. Thankyou.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-24-2012
    Location
    Stratford-upon-Avon
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Macro to Autosum variable rows above selected cell

    Hi Ciao

    Thank you for your reply. I have tried the code, which works fine, but i need it to perform the auto sum from any selected row in column D and only sum up to a blank line and not to D2. Hope you can help me.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Autosum variable rows above selected cell

    Hi, Stratfordoaks,

    there was no blank cell in Column D in your sample?

    You may utilze something like
    Please Login or Register  to view this content.
    but you need to check if the returned value is greater than 1 (which would mean no empty cells in that column).

    Ciao, '<-- Greeting
    Holger '<-- FirstName

  11. #11
    Registered User
    Join Date
    11-24-2012
    Location
    Stratford-upon-Avon
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Macro to Autosum variable rows above selected cell

    Hi Holger

    Sorry for wrong name! Please excuse my newness to macro's. Could you give me the code for doing this autosum including your code in the last reply?

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Autosum variable rows above selected cell

    Hi, Stratfordoaks,

    no problem with my name. Please find the altered code, changes are coloured in blue:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  13. #13
    Registered User
    Join Date
    11-24-2012
    Location
    Stratford-upon-Avon
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Macro to Autosum variable rows above selected cell

    Hi Holger

    Its almost perfect! It auto sums upwards from whichever row I start from in column D, but does not sum the last row at the top of the range. For example if I start in cell D11 the formula shows =SUM($D$8:$D$10) and I need it to be =SUM($D$7:$D$10) as the data is in rows D7:D10. Thank you for your help.

  14. #14
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Macro to Autosum variable rows above selected cell

    Hi, Stratfordoaks,

    please change the red lines
    Please Login or Register  to view this content.
    to read either
    Please Login or Register  to view this content.
    which switches the lines into comments the compiler will not regard when running or shorten the code by deleting them to
    Please Login or Register  to view this content.
    Ciao,
    Holger

  15. #15
    Registered User
    Join Date
    11-24-2012
    Location
    Stratford-upon-Avon
    MS-Off Ver
    Excel 2007
    Posts
    89

    Re: Macro to Autosum variable rows above selected cell

    Hi Holger

    That works perfectly now. Thank you so much for your help

+ 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