Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Feb 2004
    Location
    Houston, Texas, USA
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete Empty Cells in Table (2003/SP2)

    I am trying to remove all blank cells in a 34-page table, moving the cells with contents to the left in each instance. I know that a macro will do this but haven't written any in a few years. My logic would be something like this:

    Find Next Blank Cell
    Delete Cell
    and loop back to Find Next Blank Cell

    Can anyone help, please?

    Thanks!!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Empty Cells in Table (2003/SP2)

    Do you only want to move cells to the left, or do you also want to move them to the previous row?
    Does your table contain merged cells (it could become *very* nasty if so)
    Why do you want to do this? <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  3. #3
    Star Lounger
    Join Date
    Feb 2004
    Location
    Houston, Texas, USA
    Posts
    95
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete Empty Cells in Table (2003/SP2)

    I only want to move the cells with text to the left.

    There are merged cells in the table.

    The 34-page table was created as an indented outline with different levels of indentation in each column. Blank cells were used to space to the correct level of indentation.

    I want to remove all of the blanks so that the cells with the row number (actually the Work Breakdown Structure ID) will be in the first column in the table. Then I can simply copy the contents of the table (WBS ID and task name) into a Microsoft Project Plan.

    I've attached a very short example.

    Thanks!
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete Empty Cells in Table (2003/SP2)

    This will not be easy in Word, I think. I'd copy the table into Excel, then run the following simple macro:

    Sub RemoveLeadingBlanks()
    Dim lngMaxRow As Long
    Dim lngRow As Long
    lngMaxRow = Cells.Find(What:="*", SearchOrder:=xlByRows, _
    SearchDirection:=xlPrevious).Row
    For lngRow = 1 To lngMaxRow
    Do While Range("A" & lngRow) = ""
    Range("A" & lngRow).Delete Shift:=xlToLeft
    Loop
    Next lngRow
    End Sub

    You can then copy the result into Project.

    Note: this won't work if there are completely blank rows.

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Delete Empty Cells in Table (2003/SP2)

    The following code will do basically what you need within Word
    <pre>Sub CellMover()
    Dim aCell As Cell, aRow As Row, iCells As Integer
    For Each aRow In ActiveDocument.Tables(1).Rows
    iCells = aRow.Cells.Count
    aRow.Cells(1).Range.Text = CellTrimmer(aRow.Cells(iCells - 1).Range.Text)
    aRow.Cells(2).Range.Text = CellTrimmer(aRow.Cells(iCells).Range.Text)
    Next aRow
    End Sub

    Function CellTrimmer(str As String) As String
    Dim iLen As Integer
    iLen = Len(str)
    CellTrimmer = Left(str, iLen - 2)
    End Function</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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