+ Reply to Thread
Results 1 to 3 of 3

Move Contents of Cells and Eliminate Empty Rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-29-2012
    Location
    Calgary CA
    MS-Off Ver
    Excel 2010
    Posts
    117

    Move Contents of Cells and Eliminate Empty Rows

    Hi Gurus:

    I am trying to move contents from a specific cell to another and delete any empty rows produced(see attachment for illustation).
    Please write me a code for this task.


    Many many thanks,

    Chris

    Sample Datasheet for Code Request1-Conditioned data shift and empty row elimination.xlsx

  2. #2
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: Move Contents of Cells and Eliminate Empty Rows

    Backup data.
    Copy code to standard module.
    Run: IfBnDareEmpty

    ' For each row,
    ' if column B&D of this row are empty,
    ' move the content of column C to column C of the previouse row, if any.
    ' Do the same thing for column E and column F.
    ' Then delete row
    Sub IfBnDareEmpty()
        Dim nRow As Long
        Dim nLastRow As Long
        Dim s As String
        
        nLastRow = Cells(Rows.Count, "A").End(xlUp).Row
        For nRow = nLastRow To 1 Step -1
            If IsEmpty(Cells(nRow, "B")) _
            And IsEmpty(Cells(nRow, "D")) Then
                s = Cells(nRow, "C")
                If Len(s) Then Cells(nRow - 1, "C") = Cells(nRow - 1, "C") & s
                s = Cells(nRow, "E")
                If Len(s) Then Cells(nRow - 1, "E") = Cells(nRow - 1, "E") & s
                s = Cells(nRow, "F")
                If Len(s) Then Cells(nRow - 1, "F") = Cells(nRow - 1, "F") & s
                Rows(nRow).EntireRow.Delete
            End If
        Next nRow
    End Sub

  3. #3
    Forum Contributor
    Join Date
    06-29-2012
    Location
    Calgary CA
    MS-Off Ver
    Excel 2010
    Posts
    117

    Re: Move Contents of Cells and Eliminate Empty Rows

    OH I LOVE YOUR CODES!

    Thank you again for your timely and precise response!

    Enjoy the weekend:-)

+ 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