Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-15-2012, 10:37 PM
ubns ubns is offline Macro for table with zeros Windows 7 32bit Macro for table with zeros Office 2010 32bit
Competent Performer
Macro for table with zeros
 
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
  #2  
Old 04-16-2012, 05:07 AM
macropod's Avatar
macropod macropod is offline Macro for table with zeros Windows 7 64bit Macro for table with zeros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi umesh,


Change:
If StrTmp = "" Then .Delete
to:
If StrTmp = "" And InStr(Rng.Text, "0") > 0 Then .Delete

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to Table Style ubns Word VBA 1 04-16-2012 05:01 AM
Help with pivot table macro ejima Excel Programming 2 02-16-2012 03:45 PM
Sort table using macro saslotteroy Word VBA 2 09-15-2011 02:41 PM
Macro for table with zeros Eliminating zeros, null values and negatives in a column jannie Excel 1 06-22-2011 07:03 PM
Macro for table with zeros How Do I Replace Nulls With Zeros? deekadelic Excel 1 08-11-2006 09:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft