Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-29-2023, 09:36 PM
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 Remove parenthesis that contain four digits or etal word vba

Hi everyone,


I have such text

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 (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).

I want to remove any parenthesis that contains four digits (year) or etal only because some parentheses are important and must be maintained such as (AgNPs) or may be just year (2010).

Thanks in advance
Reply With Quote
  #2  
Old 10-29-2023, 10:50 PM
Guessed's Avatar
Guessed Guessed 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 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

First, do a wildcard search for
\(* [0-9]{4}*\)
Replace with nothing

Then if there are some et al paragraphs left, do another wildcard search
\(*et al*\)
Replace with nothing

You can record these actions to get a first draft of the code that performs it. You can then clean up the code to make it less confusing or just use it as recorded.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #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
  #4  
Old 10-30-2023, 06:57 AM
vivka vivka is offline Remove parenthesis that contain four digits or etal word vba Windows 7 64bit Remove parenthesis that contain four digits or etal word vba Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi! I think Andrew just accidentally included asterisks (It was a simple overlook, I'm sure, because his knowledge of VBA is immense). Try this to delete years in parentheses:
Code:
\([0-9]{4}\)

Last edited by vivka; 10-30-2023 at 12:52 PM.
Reply With Quote
  #5  
Old 10-30-2023, 12:19 PM
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 vivka View Post
. Try this:
Code:
\([0-9]{4}\)
Thanks, but it removes parathesis in such pattern only "(2023)", which is not my need
I want to keep parathesis in such pattern (2016), (AgNPs).
Reply With Quote
  #6  
Old 10-30-2023, 12:51 PM
vivka vivka is offline Remove parenthesis that contain four digits or etal word vba Windows 7 64bit Remove parenthesis that contain four digits or etal word vba Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Laith93, I see I have misunderstood your aim: I thought you wanted to delete only four-digit numbers in parentheses and nothing else. So my apologies to Guessed! His code should work properly but unfortnately it doesn't (you are right). I think the following will work:
" \([!\)]@[0-9]{4}*\)"
Reply With Quote
  #7  
Old 10-30-2023, 07:54 PM
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 vivka View Post
I think the following will work:
" \([!\)]@[0-9]{4}*\)"
Also, it doesn't work properly, the same action as Andrew code.
Thanks
Reply With Quote
  #8  
Old 10-31-2023, 06:21 AM
vivka vivka is offline Remove parenthesis that contain four digits or etal word vba Windows 7 64bit Remove parenthesis that contain four digits or etal word vba Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

The code I proposed [.text = " \([!\)]@[0-9]{4}*\)"] works perfectly on your sample text: it removes parentheses with years plus text, leaving intact (2016) and (AgNPs).
Reply With Quote
  #9  
Old 10-31-2023, 11:38 PM
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 vivka View Post
I think the following will work:
" \([!\)]@[0-9]{4}*\)"
Thank you so much vivka
It works perfectly now (sorry I miscopied the code)
Best Regards
Reply With Quote
  #10  
Old 11-01-2023, 04:31 AM
vivka vivka is offline Remove parenthesis that contain four digits or etal word vba Windows 7 64bit Remove parenthesis that contain four digits or etal word vba Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Thank you, laith93!
Reply With Quote
Reply

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 02:31 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