Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 10-30-2023, 05:29 AM
laith93 laith93 is offline Remove parenthesis that contain four digits or etal word vba Windows 10 Remove parenthesis that contain four digits or etal word vba Office 2019
Competent Performer
Remove parenthesis that contain four digits or etal word vba
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
First, do a wildcard search for
\(* [0-9]{4}*\)
Replace with nothing
Dear Andrew,
Thanks for your comment
It's ok may be, but it has some bugs
if apply it to this text

However, antibiotics have been used to (2016) kill harmful bacteria but inappropriate use of these materials enabled bacterial species to increase resistance to them which results in the emergence of resistance towards bacteria (Mmola et al., 2016). Using silver nanoparticles (AgNPs) could be a good alternative to antibiotics (Huh & Kwon, 2011;Ahluwalia et al., 2014; Allafchian et al., 2016; Bagherzade et al., 2017; Bar et al., 2009; Hsieh et al., 2007; Ibrahim, 2015).

The result
However, antibiotics have been used to kill harmful bacteria but inappropriate use of these materials enabled bacterial species to increase resistance to them which results in the emergence of resistance towards bacteria. Using silver nanoparticles.

Main bugs:
(2016) has been removed
(AgNPs) also has been removed
the text after (AgNPs) has been removed to the end of the paragraph
all above items must be maintained
Also, I noted for some text, it removes the text between two parentheses, in addition to the parentheses themselves (the same case when searching for et al).

Dear Andrew, I suggest merging the search for number and et al in the same condition (also has a bug, in the case of (Huh & Kwon, 2011)).
Or as I noted for all parenthesis that I want to remove, they share this format, comma space four digits ", 1234" ----> (Huh & Kwon, 2011).
So searching for this format, I think it will produce better results.
Here is my code

Code:
Sub RemoveRefParenthesis()
' code applied to selected text

Dim oRng As range
    If Len(Selection.range) = 0 Then
        MsgBox "Select the text first", vbCritical
        Exit Sub
    End If
    Set oRng = Selection.range
    With oRng.Find
        .Text = "\(*[0-9]{4}*\)"
'        .Text = "\(, [0-9]{4}*\)"
'        .Text = "\(*et al*\)"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchKashida = False
        .MatchDiacritics = False
        .MatchAlefHamza = False
        .MatchControl = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        .Execute Replace:=wdReplaceAll
    End With
End Sub
Thanks
Reply With Quote
 

Tags
find & replace, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove parenthesis that contain four digits or etal word vba How to convert text that is enclosed inside parenthesis in a word document into numbered footnotes? BobT Word 5 07-27-2018 01:17 PM
Remove parenthesis that contain four digits or etal word vba Find and remove right parenthesis and preceding 11 characters kevinbradley57 Excel Programming 11 03-25-2018 08:24 PM
Find and Replace Parenthesis with Itallics Richard Carr Word 1 01-06-2015 06:44 PM
Separate/ Remove digits from a string of Numbers QA_Compliance_Advisor Excel 3 07-23-2014 04:59 AM
Remove parenthesis that contain four digits or etal word vba Problems merging in last 4 digits of an account higher than 16 digits Glynda Mail Merge 1 04-08-2011 12:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:33 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft