+ Reply to Thread
Results 1 to 5 of 5

How to delete a blank row if the row above that is blank

  1. #1
    Registered User
    Join Date
    01-28-2014
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    50

    How to delete a blank row if the row above that is blank

    Hi guys

    I've got some code set up to add a row above any row containing the word "Task" (helpfully provided by wonderful people on site website!). I've realised that in some cases there is already an empty row, so I don't want a second blank row. How can I change the code to say add a row, unless the row is already blank?

    this is the code:

    Option Explicit

    Sub emma()
    Dim lr As Long
    lr = Range("A" & Rows.Count).End(xlUp).Row
    Dim i As Long

    Application.ScreenUpdating = False

    For i = lr To 5 Step -1
    If Range("A" & i).Value Like "Task*" Then
    Range("A" & i).EntireRow.Insert
    End If
    Next i
    Application.ScreenUpdating = True
    MsgBox ("complete")

    End Sub

    Thanks so much
    Emma

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to delete a blank row if the row above that is blank

    Try this.
    Please Login or Register  to view this content.
    PS Can you add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-28-2014
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: How to delete a blank row if the row above that is blank

    Hi

    That worked! Thanks so much for your help

    Sorry about the code tags thing.....not too sure what to use?

    Emma

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to delete a blank row if the row above that is blank

    Emma

    For the code tags, paste the code into the post, select it and then click the # button on the toolbar above the posting window.

  5. #5
    Registered User
    Join Date
    01-28-2014
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: How to delete a blank row if the row above that is blank

    Great, will remember that! Thanks for your help

    Will add reputation and mark as solved, cheers!

    Emma

+ 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 delete blank rows if column I is blank for the row
    By tiger10012 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-10-2013, 03:01 PM
  2. [SOLVED] VBA Find last row and column that contain data and delete all blank rows and blank columns
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2012, 01:07 PM
  3. Replies: 1
    Last Post: 05-10-2012, 04:58 PM
  4. [SOLVED] To delete blank rows having blank cell in the needed raws
    By Alexander_Golinsky in forum Excel General
    Replies: 4
    Last Post: 05-04-2012, 03:11 PM
  5. Delete blank row, Fill blank data, and Vlookup function
    By bolgerot in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-21-2010, 11:35 PM

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