![]() |
#1
|
|||
|
|||
![]()
I'd need a macro that scans through the whole document and deletes all table rows if the cell in the first column = $
Here's an example: ![]() |
#2
|
|||
|
|||
![]() Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 2/12/2018 Dim oTbl As Table Dim lngIndex As Long For Each oTbl In ActiveDocument.Tables For lngIndex = oTbl.Rows.Count To 1 Step -1 If Left(oTbl.Cell(lngIndex, 1).Range.Text, Len(oTbl.Cell(lngIndex, 1).Range.Text) - 2) = "$" Then oTbl.Rows(lngIndex).Delete End If Next Next lbl_Exit: Exit Sub End Sub |
#3
|
|||
|
|||
![]()
Yaay! Thanks Greg! That's working perfectly so far!
![]() |
#4
|
||||
|
||||
![]()
Hey Greg,
Here's a simpler 'If' test: If Split(oTbl.Cell(lngIndex, 1).Range.Text, vbCr)(0) = "$" Then
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Paul,
Clever and yes works in every case except the unlikely case of the $ plus a trailing paragraph mark. |
#6
|
||||
|
||||
![]()
I think you'll find it works for that, too. It won't catch $ followed by a trailing space, but even that is easily handled via a Trim wrapper.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
Paul,
I suppose we have to agree on the definition of "works." I was looking at this with "delete rows if the cell in the first column = $" as the sole condition. Where = "$" and = "$ paragraph mark" are two conditions. Mine works with the sole condition "$", yours works with both conditions and works perfectly if that is the goal. Neither works as written for the third condition "$ " Still it is a clever technique and thanks for sharing. |
#8
|
||||
|
||||
![]() Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
dwirony | Word VBA | 2 | 10-20-2016 01:31 PM |
![]() |
brunssl2 | Excel Programming | 3 | 04-28-2014 07:07 AM |
![]() |
Steve_D | Excel | 2 | 08-24-2012 09:37 PM |
![]() |
ubns | Excel Programming | 2 | 08-14-2012 02:01 AM |
How can I delete the content of a cell in column if the cell value is more than 1000? | Learner7 | Excel | 2 | 06-27-2011 05:44 AM |