+ Reply to Thread
Results 1 to 7 of 7

Insert blank rows stops running

  1. #1
    Registered User
    Join Date
    01-25-2009
    Location
    Florida, USA
    MS-Off Ver
    Excel 2003
    Posts
    78

    Insert blank rows stops running

    I have this code which adds a blank row above the name "EV01_" where it appears.
    ...which works fine, but only works for half the rows




    Please Login or Register  to view this content.


    If I have 10 rows where this name appears it adds a blank above the first 5, and leaves the remaining unchanged.
    if i have 40 rows, it adds a blank row above the first 20.

    any ideas how to correct this?

    thanks

    Jeff

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: Insert blank rows stops running

    Try:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Insert blank rows stops running

    When you insert a row, I prefer to use a reverse loop: start from the last row and go up to row 1.

    Like this :

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Insert blank rows stops running

    Hi, Jeff,

    I like the codeline
    Please Login or Register  to view this content.
    where the adding of 0 might be passed.

    Basicly the same as before but using a Withstatement for teh AcitvSheet instead of repeating it:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Registered User
    Join Date
    06-09-2014
    Posts
    7

    Re: Insert blank rows stops running

    I tried this way, uses the initial schema and goes on until the list if finished, HAHOBE fine humor about the a+0


    Please Login or Register  to view this content.
    Moderator Comment: Please read the forum rules regarding the use of code tags.
    Last edited by alansidman; 06-09-2014 at 10:15 PM. Reason: code tags added as OP is new poster.

  6. #6
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Insert blank rows stops running

    PHP Code: 
    Option Explicit

    Sub InsertBlankRows
    ()
     
    Dim Cls As RangeRng As RangeAs Long
     
     Set Rng 
    Range([a2], [a2].End(xlDown))
     
    Columns("A:A").Insert Shift:=xlToRight
     Union
    ([A1], [A1].Offset(Rng.Rows.Count)).Value "xxx.xxx"
     
    For Each Cls In Rng
        J 
    1
        Cls
    .Offset(, -1).Value "A" Right("000" CStr(J), 4)
        If 
    Left(Cls.Value5) = "EV01_" Then
            Cells
    (Rows.Count"A").End(xlUp).Offset(1).Value "A" Right("000" CStr(J), 4) & "1"
        
    End If
     
    Next Cls
     
     
    [A1].CurrentRegion.Sort Key1:=Range("A2"), Order1:=xlAscendingHeader:=xlGuess_
        OrderCustom
    :=1MatchCase:=FalseOrientation:=xlTopToBottom
     Columns
    ("A:A").Delete Shift:=xlToLeft
    End Sub 
    Last edited by FDibbins; 06-09-2014 at 10:14 PM. Reason: unnecessary web link removed

  7. #7
    Registered User
    Join Date
    01-25-2009
    Location
    Florida, USA
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Insert blank rows stops running

    Thank you for the replies,.. and solutions.

    They all worked great!!

    Many thanks!!

    Jeff

+ 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 to create a macro to insert blank rows and copy data into blank rows?
    By zodiack101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-29-2013, 01:18 PM
  2. [SOLVED] Macro to insert blank rows so that the total number of rows with data is equal to 1021
    By nsm1411 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-07-2013, 10:25 AM
  3. loop through rows for match insert blank rows with title
    By reeyu in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 07:34 AM
  4. How to remove blank rows, then insert blank row conditionally, PLUS error proof
    By GTS115 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2009, 11:39 AM
  5. why excel stops running??
    By usiddiqi in forum Excel General
    Replies: 2
    Last Post: 05-17-2006, 05:14 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