Consulting

Results 1 to 9 of 9

Thread: insert sum formulas based on worksheet data

  1. #1
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location

    insert sum formulas based on worksheet data

    Dear VBAers

    I am trying to write the code to insert the sum formulas in subtotal rows and one total column. I have attached the sheet I am working with. Basically a 12 month worksheet that is exported into excel with values. The highlighted yellow cells show what I am trying to insert (this is the basic layout I have to start with although it will fluctuate based on the data rows). Also need to work on the net row at the end but I can take a stab at that later. And, I will need to reference the report sheet I am inserting the formulas into as the report sheet is part of bigger macro file.
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,871
    The attached is a bit of a cheat, and may not be robust enough for you.
    There's a button in the vicinity of cell P6 of the sheet REPORT (2), which is how I imagine your sheet starts out as (without totals).
    Press the button, only once mind, and see if it gives the results you want.

    There are other ways…
    Attached Files Attached Files
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I'm confused

    What does the report look like before any desired changes, and what would you like it to end like?

    I see ...

    ... different formats and spacing (row 43 6000's and 57 7000's),

    ... 2 formulas (O10 and N16),but the rest of col O and col N are values
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location
    p45cal,

    Words cannot express how awesome this is, thank you. I spent the better part of my morning trying to figure out how to do this using loops, offset, copy pasting, end up, etc using vba. I opened up your code and its nothing I have every used or seen before. Actually I knew the .selection and .delete parts. I thought I knew some stuff but I just realized I haven't even left the garage. Furthermore I really appreciate your help because I felt guilty during the day that I just uploaded a file and asked for someone to help code it in lieu of providing what code I knew and adjust thru the recommendations. I was actually going to delete my post but so I glad I did not and you helped me. Thanks a bizzillion and loop that with some code for another bizzilion times!!! I believe this is not the first time you have helped me, thank you for all your efforts. Now I am going to study your code and google what the components do so I can add it to my small knowledge base. And finally, I will never upload a file without having some code, however rudimentary. This forum is a great place!!! Thanks!

  5. #5
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location
    Paul,

    The report comes as is (as values) except for the 2 cells colored yellow. That is where I entered the formulas I want (as an example for what I wanted). I was looking for sum formulas in the total rows (rows 16,20,42,54,55,63 and 65 columns C to O) and column O (all rows except blank rows - these are cross foots - old accounting term). I just cannot figure out how to define and insert the sum formulas using loops and the end up down codes. Pcal45 provided great code which does the job except for the total row but I think I can figure that out (plus I did not ask for that row for help, so he did perfect). If you want to provide some code I would appreciate that because the more code I can see and work with the more I will learn. I work with a lot of reports that come as values and I need go in and macro in the formulas where needed. The issue is the files are all different so I can have static code, rows and columns change. If you dont want to spend your time because I have a working solution that is fine I understand. Thank you for looking at my file and asking for clarity on the file and what I was looking for. I will post this thread as solved tomorrow night if you have time before then cool or tell me to wait another day as you may have more questions.

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,871
    An exercise to demonstrate flakiness:
    Before clicking the button, delete the contents of cell C30.
    Look at the mess that ensues.
    Easy enough to cater for 'though.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by SteveM99 View Post
    Paul,

    The report comes as is (as values) except for the 2 cells colored yellow. That is where I entered the formulas I want (as an example for what I wanted). I was looking for sum formulas in the total rows (rows 16,20,42,54,55,63 and 65 columns C to O) and column O (all rows except blank rows - these are cross foots - old accounting term). I just cannot figure out how to define and insert the sum formulas using loops and the end up down codes. Pcal45 provided great code which does the job except for the total row but I think I can figure that out (plus I did not ask for that row for help, so he did perfect). If you want to provide some code I would appreciate that because the more code I can see and work with the more I will learn. I work with a lot of reports that come as values and I need go in and macro in the formulas where needed. The issue is the files are all different so I can have static code, rows and columns change. If you dont want to spend your time because I have a working solution that is fine I understand. Thank you for looking at my file and asking for clarity on the file and what I was looking for. I will post this thread as solved tomorrow night if you have time before then cool or tell me to wait another day as you may have more questions.
    If you're happy

    I was just confused because there were 2 cells that needed formulas, but I didn't see why the similar cells came with values
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location
    Quote Originally Posted by p45cal View Post
    An exercise to demonstrate flakiness:
    Before clicking the button, delete the contents of cell C30.
    Look at the mess that ensues.
    Easy enough to cater for 'though.
    Wow, that is a mess.

  9. #9
    VBAX Regular
    Joined
    Dec 2015
    Posts
    57
    Location
    Quote Originally Posted by p45cal View Post
    An exercise to demonstrate flakiness:
    Before clicking the button, delete the contents of cell C30.
    Look at the mess that ensues.
    Easy enough to cater for 'though.
    Just posted another thread on same worksheet but now working on inserting a sum formula to add up the variable rows (the total rows). Not sure how to approach non-contiguous rows.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •