Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-15-2024, 02:34 AM
Howardc1001 Howardc1001 is offline Code to clear data where there are numbers and data to the right of the numbers Windows 10 Code to clear data where there are numbers and data to the right of the numbers Office 2016
Novice
Code to clear data where there are numbers and data to the right of the numbers
 
Join Date: Sep 2021
Posts: 6
Howardc1001 is on a distinguished road
Default Code to clear data where there are numbers and data to the right of the numbers


I have a word document and need all the data containing a number and the text to the right of the number to be cleared e.g 1) 2)
Reply With Quote
  #2  
Old 02-15-2024, 03:16 AM
gmaxey gmaxey is offline Code to clear data where there are numbers and data to the right of the numbers Windows 10 Code to clear data where there are numbers and data to the right of the numbers Office 2019
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

Your sample document contains of unrelated lists e.g., A) and 1) are not related. 1) is not the second level of A). So if you stick with that arrangement, you will need something like:

Code:
Sub ClearNumberedList()
Dim para As Paragraph
  For Each para In ActiveDocument.Paragraphs
    If para.Range.ListFormat.ListType = wdListSimpleNumbering Then
      If IsNumeric(Left(para.Range.ListFormat.ListString, 1)) And Right(para.Range.ListFormat.ListString, 1) = ")" Then
        para.Range.Delete
      End If
    End If
  Next para
End Sub

If you used related lists, it would be as simple as:


Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oPar As Paragraph
  For Each oPar In ActiveDocument.Range.Paragraphs
    If oPar.Range.ListFormat.ListLevelNumber = 2 Then
      oPar.Range.Delete
    End If
  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-15-2024, 04:42 AM
Howardc1001 Howardc1001 is offline Code to clear data where there are numbers and data to the right of the numbers Windows 10 Code to clear data where there are numbers and data to the right of the numbers Office 2016
Novice
Code to clear data where there are numbers and data to the right of the numbers
 
Join Date: Sep 2021
Posts: 6
Howardc1001 is on a distinguished road
Default

Many Thanks Greg for the help

Your first solution worked perfectly
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to clear data where there are numbers and data to the right of the numbers Assigning numbers to every group in a set of data Marcia Excel 5 03-30-2021 12:37 AM
Code to clear data where there are numbers and data to the right of the numbers How to optimize the data summation code for each row and column in a data rectangle area? leeqiang Excel Programming 5 10-04-2020 06:53 PM
Clear data from unlocked cells wpryan Excel Programming 5 02-25-2016 10:51 PM
Macro to recap data of same numbers Jasa P Word VBA 0 06-28-2012 02:41 AM
How to Insert a Clear, Blank page without Lines and Numbers in a Pleading Document Dirigo Word 5 09-30-2011 08:08 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:25 AM.


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