+ Reply to Thread
Results 1 to 13 of 13

Need a macro optimization to include last row with data

  1. #1
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Need a macro optimization to include last row with data

    Dear Forum,

    As per below, I am running a simple macro which has some table/row/column/margin formats and a sum at the end-below the last cell of the column with the numbers.
    My problem is that every time I need to run the macro the range of rows is different and the table format keeps the initial A1:K127 range, which also affects the sum cell. When recorded the macro I hit (Ctrl+Shift+arrows) but the macro does not consider it (to reach this way automatically all the range), can you please give me an advise on how to make it every time to consider the new range of rows?

    ---------------------------------------------------
    Please Login or Register  to view this content.
    -------------------------------------------------------------
    Last edited by arlu1201; 08-31-2012 at 09:49 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need a macro optimization to include last row with data

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature.

    ---------- Post added at 07:25 PM ---------- Previous post was at 07:25 PM ----------

    Try this
    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Need a macro optimization to include last row with data

    Thank you for notifying, well noted.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need a macro optimization to include last row with data

    Did you try the code?

  5. #5
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Need a macro optimization to include last row with data

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need a macro optimization to include last row with data

    I had corrected the code for you and given you my version (see below). Did you try it?
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Need a macro optimization to include last row with data

    I will try it tomorrow and let you know, I might need to re-post the whole macro within the code tags.thank you for helping out, I am new on vba/macros..

  8. #8
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Need a macro optimization to include last row with data

    Hello Arlette,

    Please see below the whole initial macro. Can you please do your above amendments into this one? thank you in advance

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need a macro optimization to include last row with data

    Try this
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Need a macro optimization to include last row with data

    Tried and I get errors (with debug option and highlighted in yellow).
    1.
    Please Login or Register  to view this content.
    The 'Sheet1' has always a name in the excel sheet, to bypass it i renamed it in the code. (is there a way to make it every time get the sheet's name by default cause every day it changes?)

    2.
    Please Login or Register  to view this content.
    It seems that it does not accept the table format?how can I correct this?

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need a macro optimization to include last row with data

    I had not tested the code since i would have to replicate the sheet.

    What do you want the name for Sheet1? Since it changes often, will it be the first sheet in your file? In that case, you can try
    Please Login or Register  to view this content.
    "TableStyleMedium2"
    Try removing the "" on either side.

  12. #12
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Need a macro optimization to include last row with data

    You are right, let me attach the xls. file so you may help me more easily.
    *note that the sheet name is always the first but every day changes name (actually the last 4 digits).
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    06-21-2012
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Need a macro optimization to include last row with data

    Hello Arlette,

    Can you please see my attached workbook? I have included in the workbook the macro I'm using, which is 'imperfect' because I'm forced to make the table till the 200th row so as to include every time all the data (they usually range between 50 and 180 rows)for the sum. Please have a look and advise how can I instruct excel to create the Sum under the last row which varies every time.

    Thank you very much
    ilias
    Attached Files Attached Files
    Last edited by iliasark; 09-14-2012 at 03:31 AM.

+ 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