+ Reply to Thread
Results 1 to 5 of 5

insering empty row based on a condition

  1. #1
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    insering empty row based on a condition

    Using macro, I want to add an empty row above every content in column A

    For e.g. if cell A2 has a content in it, then add an empty row above it.
    Likewise, if cell A4 has no content in it, then no need to add an empty row above it.

    Take a look at the image below
    Untitled.jpg

    I have attached a sample workbook, it contains,
    Sheet 1, the data before running the macro
    Sheet 2, shows after the data looks like after running the macro
    Sheet 3, contains a button where the macro should be inserted
    row.xls
    Last edited by darkhorse4321; 12-10-2010 at 02:17 AM.

  2. #2
    Registered User
    Join Date
    12-09-2010
    Location
    Essex, England
    MS-Off Ver
    Excel 2002
    Posts
    41

    Re: insering empty row based on a condition

    This works based on the fact that you can't set c to be row 0

    Public Sub InsertRowAboveNonEmpty()

    Dim c As Range
    Set c = Sheets(1).Cells(65536, 1).End(xlUp)

    On Error Resume Next
    Do Until Err.Number <> 0
    If Not IsEmpty(c) Then
    c.EntireRow.Insert (xlShiftDown)

    End If

    Set c = c.Offset(-1, 0)

    Loop

    End Sub

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: insering empty row based on a condition

    Hi,

    One way

    Please Login or Register  to view this content.
    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: insering empty row based on a condition

    Try this
    Please Login or Register  to view this content.
    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Forum Contributor
    Join Date
    10-27-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    107

    Re: insering empty row based on a condition

    Thanks guys for your time and help. It works

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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