Solved

upgrading short code that deletes empty rows in excel

Posted on 2008-06-11
4
296 Views
Last Modified: 2010-04-21
hi,
i have the attached code, that currently deletes every empty row in a word table (also rows with only numbering bullet). i need to upgrade this code so that also if the row cells containes only spaces (" "), it should also be deletd.
appreciate your kind help :)
Sub DelRows()
    Dim tbl As Table
    Dim rw As Row
    
    Set tbl = ActiveDocument.Tables(1)
    For Each rw In tbl.Rows
        If rw.Range.Characters.Count - rw.Range.Cells.Count = 1 Then
            rw.Delete
        End If
    Next rw
End Sub

Open in new window

0
Comment
Question by:Or_A
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:danengle
ID: 21763261
I'm not familiar with the syntax for acquiring the actual cell content so am leaving that to you, but the logic should work:


    For Each rw In tbl.Rows
        If rw.Range.Characters.Count - rw.Range.Cells.Count = 1 Then
            rw.Delete
' replace 
        elseif replace(rw.<whatevertoretrievecontent>, " ", "") = "" then
            rw.Delete
        End If
    Next rw

Open in new window

0
 
LVL 5

Expert Comment

by:danengle
ID: 21763295
Actually, upon further inspection, this deletes just empty cells?  based on the sub you posted, it appears it will delete everything.

Also, for the first If, couldn't it just use:
If rw.Range.Characters.Count = 0 then rw.delete

?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 21764553
Not sure why this is in Zone VBScript. If you really are using VBScript, these procedures need a bit of tweaking

Similar, but slightly different technique.
Sub DelRows2()
    Dim tbl As Table
    Dim rw As Row
    
    Set tbl = ActiveDocument.Tables(1)
    For Each rw In tbl.Rows
        If Len(Replace$(rw.Range.Text, " ", "")) = (rw.Cells.Count + 1) * 2 Then
            rw.Delete
        End If
    Next rw
End Sub

Open in new window

0
 

Author Closing Comment

by:Or_A
ID: 31466297
worked great, thanks!
but i didnt understand your question, what i've written is not in VB?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question