Consulting

Results 1 to 2 of 2

Thread: VBA To Remove Rows From Table

  1. #1
    VBAX Regular
    Joined
    Sep 2016
    Posts
    16
    Location

    VBA To Remove Rows From Table

    Hi,

    Wonder if someone could help at all please?

    I'm after some VBA code to use in Word that will look in any USER HIGHLIGHTED table, will look in the 2nd column and if it says "Error", it will delete the entire row from the table. It will then loop through and delete each row as appropriate.

    Any ideas please?

    Thanks so much!

  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 lngIndex As Long
      With Selection.Tables(1)
        For lngIndex = .Rows.Count To 1 Step -1
          If Left(.Cell(lngIndex, 2).Range.Text, Len(.Cell(lngIndex, 2).Range.Text) - 2) = "Error" Then
            .Rows(lngIndex).Delete
          End If
        Next
      End With
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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