Consulting

Results 1 to 3 of 3

Thread: Insert rows condition but ingore the blank cells.

  1. #1
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location

    Insert rows condition but ingore the blank cells.

    Hi Everyone,


    I have this code below that it will insert a row in column A if there is a text name "Total". But I would like to add a condition. If the text "Total" has a blank cell underneath do not insert row.



    [vba]
    Sub Test()
    Range("A65536").End(xlUp).Offset(-2, 0).Select
    Do Until ActiveCell.Row = 1
    If Right(ActiveCell, 5) = "Total" Then
    Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(1, 0)).EntireRow.Insert
    ActiveCell.Offset(-1, 0).Select
    Else
    ActiveCell.Offset(-1, 0).Select
    End If
    Loop

    End Sub
    [/vba]



    I tried to modify it like this but no avail.


    [vba]
    Sub Test()
    Range("A65536").End(xlUp).Offset(-2, 0).Select
    Do Until ActiveCell.Row = 1
    If Right(ActiveCell, 5) = "Total"
    If <>"" Then
    Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(1, 0)).EntireRow.Insert
    ActiveCell.Offset(-1, 0).Select
    Else
    ActiveCell.Offset(-1, 0).Select
    End If
    Loop

    End Sub
    [/vba]

    I left an example workbook below.
    SHAZAM!

  2. #2
    VBAX Mentor MaximS's Avatar
    Joined
    Sep 2008
    Location
    Stoke-On-Trent
    Posts
    360
    Location
    try this:

    [VBA]Sub Test()
    Range("A65536").End(xlUp).Offset(-2, 0).Select
    Do Until ActiveCell.Row = 1
    If Right(ActiveCell, 5) = "Total" And ActiveCell.Offset(1, 0) <> "" Then
    Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(1, 0)).EntireRow.Insert
    ActiveCell.Offset(-1, 0).Select
    Else
    ActiveCell.Offset(-1, 0).Select
    End If
    Loop
    End Sub[/VBA]

  3. #3
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    Quote Originally Posted by MaximS
    try this:

    [vba]Sub Test()
    Range("A65536").End(xlUp).Offset(-2, 0).Select
    Do Until ActiveCell.Row = 1
    If Right(ActiveCell, 5) = "Total" And ActiveCell.Offset(1, 0) <> "" Then
    Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(1, 0)).EntireRow.Insert
    ActiveCell.Offset(-1, 0).Select
    Else
    ActiveCell.Offset(-1, 0).Select
    End If
    Loop
    End Sub[/vba]


    Perfect!!! Thank You.
    SHAZAM!

Posting Permissions

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