Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-12-2018, 06:47 AM
Btop Btop is offline Macro delete table rows if cell in first column = $ Windows 10 Macro delete table rows if cell in first column = $ Office 2016
Novice
Macro delete table rows if cell in first column = $
 
Join Date: Feb 2018
Posts: 17
Btop is on a distinguished road
Default Macro delete table rows if cell in first column = $


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:

Reply With Quote
  #2  
Old 02-12-2018, 07:19 AM
gmaxey gmaxey is offline Macro delete table rows if cell in first column = $ Windows 7 32bit Macro delete table rows if cell in first column = $ Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 02-12-2018, 08:38 AM
Btop Btop is offline Macro delete table rows if cell in first column = $ Windows 10 Macro delete table rows if cell in first column = $ Office 2016
Novice
Macro delete table rows if cell in first column = $
 
Join Date: Feb 2018
Posts: 17
Btop is on a distinguished road
Default

Yaay! Thanks Greg! That's working perfectly so far!
Reply With Quote
  #4  
Old 02-12-2018, 01:40 PM
macropod's Avatar
macropod macropod is offline Macro delete table rows if cell in first column = $ Windows 7 64bit Macro delete table rows if cell in first column = $ 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

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]
Reply With Quote
  #5  
Old 02-13-2018, 03:29 PM
gmaxey gmaxey is offline Macro delete table rows if cell in first column = $ Windows 7 32bit Macro delete table rows if cell in first column = $ Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Paul,

Clever and yes works in every case except the unlikely case of the $ plus a trailing paragraph mark.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 02-13-2018, 03:32 PM
macropod's Avatar
macropod macropod is offline Macro delete table rows if cell in first column = $ Windows 7 64bit Macro delete table rows if cell in first column = $ 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

Quote:
Originally Posted by gmaxey View Post
works in every case except the unlikely case of the $ plus a trailing paragraph mark.
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]
Reply With Quote
  #7  
Old 02-13-2018, 03:58 PM
gmaxey gmaxey is offline Macro delete table rows if cell in first column = $ Windows 7 32bit Macro delete table rows if cell in first column = $ Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #8  
Old 02-13-2018, 05:36 PM
macropod's Avatar
macropod macropod is offline Macro delete table rows if cell in first column = $ Windows 7 64bit Macro delete table rows if cell in first column = $ 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

Quote:
Originally Posted by gmaxey View Post
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 "$ "
I see now the distinction you were drawing.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro delete table rows if cell in first column = $ Need macro to delete a column with a blank cell dwirony Word VBA 2 10-20-2016 01:31 PM
Macro delete table rows if cell in first column = $ Macro for Column to Rows Data brunssl2 Excel Programming 3 04-28-2014 07:07 AM
Macro delete table rows if cell in first column = $ Macro to conditionally delete rows Steve_D Excel 2 08-24-2012 09:37 PM
Macro delete table rows if cell in first column = $ Macro to delete rows with all empty cells 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:44 PM.


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