+ Reply to Thread
Results 1 to 5 of 5

Reformatting macro which needs to insert rows after a variable number of records.

  1. #1
    Registered User
    Join Date
    10-12-2023
    Location
    Northants, England
    MS-Off Ver
    365
    Posts
    2

    Reformatting macro which needs to insert rows after a variable number of records.

    Hi Guys

    I'm new to the Forum.

    I have an Excel table of some 600+ records and have devised a macro (Excel_Macro_1) which reformats the table, sorts it on one column into three categories ‘blank’, ‘Air’ and ‘emag’ and adds three functions to count the number of records in each category (abridged version of table attached as Example_1).

    I require the macro then to insert a block of 5 further blank rows to fall into the ‘blank’ category. I’ve tried inserting 5 rows as the last 5 rows in the ‘blank’ category by selecting the first 5 rows in the ‘Air’ category and, from the context menu, selecting ‘insert’. By doing so, the addresses of the inserted rows are hard coded into the macro which becomes a problem if the ‘blank’ category contains more records than when the macro was first/last run, resulting in the blank rows being spread between two locations in the table.

    I need somehow to instruct the macro to insert the 5 rows by reference to ‘the first row which is not blank’ but achieving this is beyond my Excel knowledge.

    For the purposes of this query, sensitive data have been removed from the attached Excel file. The macro code however reflects the original spreadsheet upon which it was based.

    I would appreciate some help.

    PeterWB

    Excel_Macro_1.docxExample_1.xlsx

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,242

    Re: Reformatting macro which needs to insert rows after a variable number of records.

    Since you have counted empty cells, you can specify from which row of the table data to insert empty rows (the result from cell L1 +1) and expand the range to five (Resize(5) ).
    After recording the macro, it is a good idea to get rid of all the Selects from the code by modifying the code accordingly.
    Please Login or Register  to view this content.
    Artik

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,588

    Re: Reformatting macro which needs to insert rows after a variable number of records.

    PeterWB,

    try
    Please Login or Register  to view this content.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    10-12-2023
    Location
    Northants, England
    MS-Off Ver
    365
    Posts
    2

    Re: Reformatting macro which needs to insert rows after a variable number of records.

    Hi Artik

    That works fine - thank you so much for your help. I'm sure I will be back in the future.

    PeterWB

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,434

    Re: Reformatting macro which needs to insert rows after a variable number of records.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. How do you insert a variable number of blank rows?
    By max3732 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2022, 07:34 AM
  2. [SOLVED] Need macro to insert rows & convert sequence of records into new sheet
    By tabkaz in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-20-2016, 10:28 AM
  3. Macro to insert a variable number of rows into a variable location
    By TheClaw2323 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-08-2015, 05:31 AM
  4. [SOLVED] Macro code to insert 3 rows on spreadsheet with variable number of rows
    By D18GE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2013, 07:33 AM
  5. Insert Next? Or insert a variable number of records...how?
    By Tom MacKay in forum Excel General
    Replies: 0
    Last Post: 04-20-2006, 05:50 PM
  6. Need to insert formula to a variable number of rows
    By edoc abv in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2005, 12:05 AM
  7. insert variable number of rows
    By tina in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2005, 10:06 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