+ Reply to Thread
Results 1 to 8 of 8

Create Macro to Add Rows when the # of rows vary each month

  1. #1
    Registered User
    Join Date
    06-13-2017
    Location
    NC
    MS-Off Ver
    2010
    Posts
    9

    Create Macro to Add Rows when the # of rows vary each month

    Hi,

    I am trying to create a macro that will do some formatting and one of the things I would like to do is for the macro to add up several different columns. The thing is the number of rows will vary from month to month and I would like totals to be just underneath the last row. What's the best way to do this?

    I have attached a sample of my document.

    Thanks for the help.
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Create Macro to Add Rows when the # of rows vary each month

    The easiest way is probably to calculate the last row, then put a sum formula in the columns you want totalled... Assuming column A always has data, something like this:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    06-13-2017
    Location
    NC
    MS-Off Ver
    2010
    Posts
    9

    Re: Create Macro to Add Rows when the # of rows vary each month

    Hi Arkadi,

    Thanks for the help. Unfortunately, as I am new to macros that means nothing to me. How would I use what you provided to create a macro? How would I make the changes for the columns I want added up?

    Debi

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Create Macro to Add Rows when the # of rows vary each month

    Hi debi,

    What I provided is not so much used to make a macro.... it IS a macro I realize you may want to integrate it into other code, if so maybe provide what you have and I can help.

    This line:

    Please Login or Register  to view this content.
    uses the variable "lr" (which is the last row with data in it in column A, to build the forumla for the total of column H, summing the second row to the last one.
    if you want to change that column, just change the letter H (3 places) to another column letter, or if you simply want to add other totals, copy the line, and paste it either above or below, and change the H in the copy to match the other column's letter.
    Hope that helps a little, but feel free to come back with more questions.
    Last edited by Arkadi; 06-16-2017 at 03:28 PM.

  5. #5
    Registered User
    Join Date
    06-13-2017
    Location
    NC
    MS-Off Ver
    2010
    Posts
    9

    Re: Create Macro to Add Rows when the # of rows vary each month

    Hi,

    I have attached one of my sample spreadsheets and then my formatting macro as I wasn't sure where to insert it to the other tasks within the macro.

    Thanks for the help.
    Attached Files Attached Files
    Last edited by debi0662; 06-17-2017 at 08:40 AM.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Create Macro to Add Rows when the # of rows vary each month

    Hi debi,

    I noticed you have a recorded macro, which is a great tool, but often can use some cleanup. I took the liberty of making some changes, in particular removing tasks where a range or cell is selected, and then the code uses "selection." ....
    In those cases it is almost always better to work with the range itself. Have a look and see if this produces the desired result?:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 06-19-2017 at 11:02 AM.

  7. #7
    Registered User
    Join Date
    06-13-2017
    Location
    NC
    MS-Off Ver
    2010
    Posts
    9

    Re: Create Macro to Add Rows when the # of rows vary each month

    Thank you so much. That works great. Do you have a suggestion of a site that has detailed explanation on how to learn advanced macros?

    Debi

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Create Macro to Add Rows when the # of rows vary each month

    Glad to help

    This thread is full of suggestions: https://www.excelforum.com/excel-pro...materials.html

    By using the recorder you will get a lot of help, and as you practice more, you will see that a lot can just be cleaned up after you have the basic structure.
    Google was my best friend for learning... I simply googled what I was trying to do, and read some possible approaches, I wish I'd found this forum earlier on, but it has helped me a lot.

    Please remember to mark the thread as solved if your question was resolved? Thanks in advance.

+ 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] Macro to extract Rows Colored with Yellow Fill and create a new sheet as per current month
    By prkhan56 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-10-2016, 04:54 AM
  2. Macro to copy table from sheet1 to sheet2 (qty of rows may vary)
    By arkharova.s in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-18-2014, 03:54 AM
  3. macro to copy table from sheet1 to sheet2 (# of rows in table may vary everytime)
    By arkharova.s in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2014, 03:18 AM
  4. [SOLVED] VBA to create a chart when data can vary in column position and rows
    By MalibuLX3 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-21-2013, 11:21 AM
  5. [SOLVED] Macro To AutoSum Columns With Rows That Will Vary When The Report Is Run
    By Macro Fool in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-17-2012, 10:54 AM
  6. Replies: 2
    Last Post: 07-06-2012, 02:38 PM
  7. Using a macro to delete last 4 rows and last 2 columns which vary
    By Shirley Munro in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-01-2005, 12:05 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