#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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 |
#3
|
|||
|
|||
Quote:
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 |
#4
|
|||
|
|||
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. |
#5
|
|||
|
|||
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). |
#6
|
|||
|
|||
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}*\)" |
#7
|
|||
|
|||
Also, it doesn't work properly, the same action as Andrew code.
Thanks |
#8
|
|||
|
|||
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).
|
#9
|
|||
|
|||
Thank you so much vivka
It works perfectly now (sorry I miscopied the code) Best Regards |
#10
|
|||
|
|||
Thank you, laith93!
|
Tags |
find & replace, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
Problems merging in last 4 digits of an account higher than 16 digits | Glynda | Mail Merge | 1 | 04-08-2011 12:17 AM |