Thread: [Solved] Macro for table with zeros
View Single Post
 
Old 04-15-2012, 10:37 PM
ubns ubns is offline Windows 7 32bit Office 2010 32bit
Competent Performer
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default Macro for table with zeros

Hi

The following code works superb, however it also deletes the blank rows.

what should be changed to just delete the rows with zeros and do not touch the blank rows.

regards

Umesh

Code:
Sub CleanTables()
Application.ScreenUpdating = False
Dim oTbl As Table, Rng As Range, i As Long, j As Long, StrTmp As String
With ActiveDocument
  For Each oTbl In .Tables
    On Error Resume Next
    With oTbl
      j = .Columns.Count
      For i = .Rows.Count To 1 Step -1
        With .Rows(i)
          If .Cells.Count > 1 Then
            Set Rng = .Range
            Rng.Start = .Cells(2).Range.Start
            StrTmp = Replace(Replace(Replace(Replace(Rng.Text, Chr(7), ""), vbCr, ""), " ", ""), "0", "")
            If StrTmp = "" Then .Delete
          End If
        End With
      Next
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub

Last edited by macropod; 04-16-2012 at 05:06 AM. Reason: Added code structure & tags
Reply With Quote