PDA

View Full Version : [SOLVED:] Delete Text Found Only in Column 1 of Table



dj44
11-18-2016, 07:47 AM
Hi folks,:)

Good day!

I just wanted to delete a word from Column 1

I can't make it work, and I did try many things, I also tried a different version,:(




Sub DeleteTextColumn1()

Dim oTable As Table
Dim oRng As Range
Dim i As Integer
Set oTable = ActiveDocument.Tables(1)


Set oRng = oTable.Columns(1) ' Tried .Cell


With oRng.Find
Do While .Execute(Findtext:="Friday")
If oRng.InRange(oTable.Range) Then

oRng.Delete

End If
oRng.Collapse 0
Loop
End With

End Sub


The intelisensce has not been of mutch help either

Any tips welcome

gmaxey
11-18-2016, 03:24 PM
Sub DeleteTextColumn1()
Dim oTable As Table
Dim oCell As Cell
Dim oRng As Range
Set oTable = ActiveDocument.Tables(1)
For Each oCell In oTable.Range.Cells
If oCell.Range.Information(wdEndOfRangeColumnNumber) = 1 Then
Set oRng = oCell.Range
With oRng.Find
While .Execute(Findtext:="Friday")
If oRng.InRange(oCell.Range) Then
oRng.Delete
oRng.Collapse 0
End If
Wend
End With
End If
Next oCell
End Sub

dj44
11-18-2016, 04:10 PM
Hi Greg,

Nice day to you.:)


Thanks ever so much.
I was feeling really down about not being able to fix this.
I don't like to post too much as its good for me to learn the art, but then I get stuck and i do have to fight with google:dau:

These 2 lines - I have not seen anywhere on my travels through the sphere

For Each oCell In oTable.Range.Cells
If oCell.Range.Information(wdEndOfRangeColumnNumber) = 1 Then


Sometimes I can guess and make it happen, but programming doesn’t like that as I know too well.

Thanks for coding this
And you get far too less credit for helping us dumb newbies - all the time so thank you Greg, a great asset to the vba world

And you have a great weekend now
:beerchug:

gmaxey
11-18-2016, 04:24 PM
Well thanks for the credit!