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?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.