×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Looping through a word doc to delete rows

Looping through a word doc to delete rows

Looping through a word doc to delete rows

(OP)
I have a word table that is populated by Excel VBA as shown below:-

CODE -->

wordDoc.Tables(4).Cell(2, 1).Range.Text = "    " & Range("O19").Value & "   Way Flush Mounting, Programmable Alarm Annunciator." 'Product code
    wordDoc.Tables(4).Cell(5, 1).Range.Text = Range("O25").Value 'Window size
    wordDoc.Tables(4).Cell(8, 1).Range.Text = Range("O13").Value & "W" & Range("O14").Value & "H" 'Panel Size
    wordDoc.Tables(4).Cell(12, 1).Range.Text = Range("O26").Value 'Pushbutton
    wordDoc.Tables(4).Cell(14, 1).Range.Text = Range("O19").Value & "A" 'Channel Count
    wordDoc.Tables(4).Cell(15, 1).Range.Text = Range("P24").Value ' Unarmed
    wordDoc.Tables(4).Cell(16, 1).Range.Text = Range("R25").Value 'Illumination
    wordDoc.Tables(4).Cell(17, 1).Range.Text = Range("O27").Value 'RR
    wordDoc.Tables(4).Cell(18, 1).Range.Text = Range("R26").Value 'Trop
    wordDoc.Tables(4).Cell(19, 1).Range.Text = Range("O29").Value 'FCV
    wordDoc.Tables(4).Cell(20, 1).Range.Text = Range("P33").Value 'Comms
    wordDoc.Tables(4).Cell(21, 1).Range.Text = Range("P32").Value 'GFI
    wordDoc.Tables(4).Cell(22, 1).Range.Text = Range("L44").Value 'Logo
    wordDoc.Tables(4).Cell(24, 1).Range.Text = Range("O28").Value 'SEC
    wordDoc.Tables(4).Cell(29, 1).Range.Text = Range("Q76").Value 'Option
    wordDoc.Tables(4).Cell(30, 3).Range.Text = Range("B3").Value 'Part number 


In some instances it places an "X" in column 1 as shown below
[img https://res.cloudinary.com/engineering-com/image/u...

I use the following code to successfully to delete other rows with the "X", but it is failing to delete these two and I cannot fathom why. Any help apprecaited.

CODE -->

With wordDoc.Tables(4)
 For r = 1 To .Rows.Count
 If .Cell(r, c).Range.Text Like "*" & "X" & "*" Then
 wordDoc.Tables(4).Rows(r).Delete
 End If
 Next r
 End With 

RE: Looping through a word doc to delete rows

Without going dipper into it, have you tried to do it backwards:

CODE

With wordDoc.Tables(4)
   For r = .Rows.Count To 1 Step -1   'Thank you strongm :-)
       If .Cell(r, c).Range.Text Like "*" & "X" & "*" Then
           wordDoc.Tables(4).Rows(r).Delete
       End If
   Next r
End With 

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Looping through a word doc to delete rows

(psst: Step -1)

RE: Looping through a word doc to delete rows

Quote (davefish)

I use the following code to successfully to delete other rows with the "X"

From the provided code (Like "*" & "X" & "*"), it looks to me that you delete the rows when the cell contains X, so not only X by itself, but also "Malcolm X", "X-Factor", "ABCXYZ", etc.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Looping through a word doc to delete rows

(OP)
@Andrzejek
@strongm

Great job! Thank you both for your suggestion it worked straight away

RE: Looping through a word doc to delete rows

davefish,
If one or more of the posts helped you with your issue, consider clicking the "Great post!" link.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Looping through a word doc to delete rows

Hmmmm?

Out of 169 posting encounters on Tek-Tips, the OP had expressed with a little purple star only twice in 20 years.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

You Matter...
unless you multiply yourself by the speed of light squared, then...
You Energy!

RE: Looping through a word doc to delete rows

Simpler:

CODE

With wordDoc.Tables(4)
  For r = .Rows.Count To 1 Step -1
    If Split(.Cell(r, 1).Range.Text, vbCr)(0) = "X" Then .Rows(r).Delete
  Next r
End With 

Cheers
Paul Edstein
[Fmr MS MVP - Word]

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close