Results 1 to 10 of 10

Thread: inserting a row(empty) afther each 4 rows of my data

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0
    Mr. Rick
    your code is great but it will not work after while ..
    Try to put any numeric values in range("A1:A102") for example .. and test your code
    you'll find that the last empty row is row 100 only !!

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by KingTamo View Post
    Mr. Rick
    your code is great but it will not work after while ..
    Try to put any numeric values in range("A1:A102") for example .. and test your code
    you'll find that the last empty row is row 100 only !!
    Good catch! Thanks for catching that... I had forgotten to account for the fact that the last row changes as the rows are inserted which is easily accounted for...

    Code:
    Sub Test()
      Dim R As Long
      For R = 5 To 5 * Cells(Rows.Count, "A").End(xlUp).Row Step 5
        Rows(R).Insert
      Next
    End Sub
    If the OP does not want to watch the screen jumping around, screen updating can be turned off, although then there is no visual feedback as to the macro's progress which may be important if there are a lot of rows to process (I have a fairly fast computer and the wait was quite noticeable for 20,000 rows).

    Code:
    Sub Test()
      Dim R As Long
      Application.ScreenUpdating = False
      For R = 5 To 5 * Cells(Rows.Count, "A").End(xlUp).Row Step 5
        Rows(R).Insert
      Next
      Application.ScreenUpdating = True
    End Sub

Similar Threads

  1. Replies: 2
    Last Post: 03-08-2014, 02:49 AM
  2. Skip empty row and fetch values from other rows
    By dhivya.enjoy in forum Excel Help
    Replies: 1
    Last Post: 11-08-2013, 07:44 PM
  3. Sending Data From User Form To First Empty Row Of Sheets
    By paul_pearson in forum Excel Help
    Replies: 21
    Last Post: 08-14-2013, 11:04 PM
  4. Replies: 5
    Last Post: 07-11-2013, 07:31 AM
  5. Delete Empty Rows
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 04-28-2011, 02:13 AM

Posting Permissions

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