Consulting

Results 1 to 2 of 2

Thread: Word Table - Delete Rows where Cell Values all = 0

  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    44
    Location

    Word Table - Delete Rows where Cell Values all = 0

    Hi all

    I have a document with a large table that will be populated with information as per the example below.

    Type 1 Type 2 Type 3 Type 4
    Matter 1 0% 2% 3% 1%
    Matter 2 0% 0% 0% 0%
    Matter 3 1% 0% 4% 0%

    I need a macro to recognize when all 4 cells in a row have a 0% value and then delete those rows -e.g. 'Matter 2' in the above example. For the avoidance of doubt, other rows can remain where one ore more cells in that row has a value of 0% provided that not all 4 cells in that row are 0%.

    Any thoughts would be great.

    Thanks,
    AJHEZ

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oTbl As Table
    Dim lngIndex As Long, lngCell As Long
    Dim bKill As Boolean
      Set oTbl = Selection.Tables(1)
        For lngIndex = oTbl.Rows.Count To 2 Step -1
          bKill = True
          For lngCell = 2 To 5
            If Left(oTbl.Cell(lngIndex, lngCell).Range.Text, 2) <> "0%" Then
              bKill = False
              Exit For
            End If
            If bKill Then oTbl.Rows(lngIndex).Delete
          Next lngCell
        Next lngIndex
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Tags for this Thread

Posting Permissions

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