+ Reply to Thread
Results 1 to 8 of 8

How to apply macro to a range, even if additional rows are added

  1. #1
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    How to apply macro to a range, even if additional rows are added

    I have the following macro applied to a selected range of cells:

    Please Login or Register  to view this content.

    (I have split up the ranges because it would not let me fit them all into one range)

    With this macro if I type anything other than 0 in, for example cell B7, then a tick appears in cell B7, etc.

    This macro works well however when I add a row inside the above range the macro does not apply to the whole range anymore.

    I would like to know if there is any way that I could apply this macro to the cells within the above range, including any additional rows that are inserted within the range.

  2. #2
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: How to apply macro to a range, even if additional rows are added

    Try this;
    Please Login or Register  to view this content.
    If I helped in any way, please click the star

  3. #3
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Re: How to apply macro to a range, even if additional rows are added

    Thanks but this didn't limit the macro to the above range (the number of rows it abblied to did not stop at row 18), and also a tick only appeared in columns C - I if there was already one in column B on that particular row

  4. #4
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: How to apply macro to a range, even if additional rows are added

    Quote Originally Posted by Lowa View Post
    Thanks but this didn't limit the macro to the above range (the number of rows it abblied to did not stop at row 18), and also a tick only appeared in columns C - I if there was already one in column B on that particular row
    Of course it doesn't limit the range to row 18 anymore. You didn't want it to. You wrote;
    Quote Originally Posted by Lowa View Post
    when I add a row inside the above range the macro does not apply to the whole range anymore.

    I would like to know if there is any way that I could apply this macro to the cells within the above range, including any additional rows that are inserted within the range.
    So, it sounded like you wanted the range to expand as your data rows expand. That's what I gave you.

    Secondly, your code has nothing to do with tic marks.
    If you want tic marks to appear, then change this;
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    Last edited by Jim885; 11-10-2014 at 10:17 PM.

  5. #5
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: How to apply macro to a range, even if additional rows are added

    If you are inserting rows between row 7 and 18 and you have more rows under row 18 that you don't want the macro to affect, then each time you insert another row between row 7 and 18 you will have to manually adjust the code to accommodate for the extra row. I see no other way around this.

    So you can use this code and simply change the number highlighted in red to adjust for the newly inserted row(s) as you add them.
    Please Login or Register  to view this content.
    Last edited by Jim885; 11-10-2014 at 10:26 PM.

  6. #6
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: How to apply macro to a range, even if additional rows are added

    I see that you got the below code from TMS in this thread: http://www.excelforum.com/excel-prog...ple-cells.html


    Please Login or Register  to view this content.
    I don't know why you would have changed it to what you did in your first post in this thread. It seemed to work perfectly as TMS wrote it.
    So again, if you add rows then just change the value of I18 as you need.

  7. #7
    Registered User
    Join Date
    11-10-2014
    Location
    Australia
    MS-Off Ver
    2019
    Posts
    38

    Re: How to apply macro to a range, even if additional rows are added

    Sorry I didn't explain myself properly,

    I copied and pasted your original reply that had B7:I in the range instead of B7:I18. I guess the macro stretched down so many rows because I didn't have '18' after the 'I' in the range.

    Also I have the 'ü' character in my code because I changed the font in the selected cells to 'windings', which results in a 'tick'.

    Also in the thread that TMS posted in I used the other code that he/she posted and just added in the cells that I wanted. i.e.:

    Please Login or Register  to view this content.
    Anyway, you have a point I could just manually change the '18' in the range to whatever row I want it to finish on.

    Thankyou for your help

    If you think of any way to automate the process please let me know

  8. #8
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: How to apply macro to a range, even if additional rows are added

    Quote Originally Posted by Lowa View Post

    I copied and pasted your original reply that had B7:I in the range instead of B7:I18. I guess the macro stretched down so many rows because I didn't have '18' after the 'I' in the range.
    Yes, the first code I gave you allows the range to be dynamic (the range will extend / grow to the last row even after new rows are added, time and time again). Whereas, B7:I18 is a fixed range that never changes. Thus, if you add/insert a row between row 7 and row 18, row 18 will become row 19 and will no longer be included in the original rage of B7:I18

    Quote Originally Posted by Lowa View Post
    Also I have the 'ü' character in my code because I changed the font in the selected cells to 'windings', which results in a 'tick'.
    OK, so the code is correct, you just had to format the font of the cells in the range of B7 to I18 as windings to achieve the tic mark.

    Quote Originally Posted by Lowa View Post

    Anyway, you have a point I could just manually change the '18' in the range to whatever row I want it to finish on.

    Thankyou for your help

    If you think of any way to automate the process please let me know
    You are welcome. Please mark this thread as SOLVED.
    Best of luck with your project.

+ 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. Macro to apply formatting to an unknown range of rows & columns
    By anya1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-19-2013, 09:07 PM
  2. Active X (Macro) to Sort data range to included added rows
    By tims31 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-14-2012, 01:21 PM
  3. Format range when new rows added
    By ahartman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2009, 09:23 AM
  4. [SOLVED] Apply fomulas to additional worksheets as added
    By Brent E in forum Excel General
    Replies: 2
    Last Post: 05-25-2006, 04:40 PM
  5. [SOLVED] Copy Range with Additional Rows to New Workbook
    By Kim in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-28-2006, 12:30 AM

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