Delete values in last cell of rows based on values in other cells

Dear Experts:

My current document has hundreds of tables. I would like to perform the following task using VBA.

As soon as the macro hits the value '99-99' (The value '99-99' is always located in the first cell of any row) in any of the rows, the contents of the last cell in that row is to be deleted.

All of the tables in this document feature the exact same number of columns.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Possibility for a sample document?
Chris BottomleySoftware Quality Lead EngineerCommented:

I was concerned to avoid iterating on row as this would be inefficient so please try the following on a copy of your data:

Sub Q_28270411_1()
Dim tbl As Table
Dim cols As Integer
Dim intCol As Integer
Dim rng As Range
Dim subRange As Range

    Set rng = ActiveDocument.Range
    With rng.Find
        .Text = "99-99"
        Do While .Execute(Forward:=True) = True
            If rng.Information(wdWithInTable) Then
                Set subRange = ActiveDocument.Range(rng.Start, rng.End)
                subRange.Collapse Direction:=wdCollapseEnd
                If subRange.Cells(1).ColumnIndex = 1 Then
'                    Debug.Print rng.Tables(1).Rows(rng.Cells(1).RowIndex).Cells(rng.Tables(1).Columns.Count).Range.Text
                    rng.Tables(1).Rows(rng.Cells(1).RowIndex).Cells(rng.Tables(1).Columns.Count).Range.Text = ""
                End If
            End If
    End With

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Hi Chis,

great job. Works like a charm. Saves me lots of time. Thank you very much for your swift and professional support.

Regards, Andreas
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.