Conditionally delete rows in currentliy selected table

Dear Experts:

On the currently selected table I would like to perform the following actions using VBA

The macro is to loop thru the first column of the selected table and look for the term 'error' there. If found the whole row is to be deleted. Of course there could be many cells in the first column where this term 'error' occurs.

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

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Fabrice LambertFabrice LambertCommented:
Do you want to do that with MS Excel or MS Access ?

With MS Excel, you can use the delete methode of the range object.
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet

Set wb = ThisWorkbook
Set ws = wb.Worksheets(1)
ws.rows(5).Delete shift:=xlUp

Open in new window


With Access, you can use a query.
0
Andreas HermleTeam leaderAuthor Commented:
Hi Farbrice

thank you very much for your quick help. I was posting his question on the Word for Windows Section :-)
0
Rgonzo1971Commented:
Hi,

pls try
Sub macro()

Set tbl = Selection.Tables(1)
For idx = tbl.Columns(1).Cells.Count To 1 Step -1
    Set cel = tbl.Columns(1).Cells(idx)
    If Len(cel.Range.Text) = 7 Then 'error
        If InStr(1, cel.Range.Text, "error", vbTextCompare) Then
            tbl.Rows(cel.RowIndex).Delete
        End If
    End If
Next


End Sub

Open in new window

Regards
1

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 Rafalel,

works great as always :-)

Thank you very much for your superb help. I really appreciate it. Regards, Andreas
0
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
VBA

From novice to tech pro — start learning today.