PDA

View Full Version : [SOLVED:] Deleting specific text, but not all, in parentheses



AshZM
08-28-2022, 12:51 PM
Hi, I have been trying to solve this for days. I have tried manipulating every example I could find online, but nothing works the way I need it. I just can't figure out how to have the VBA only process something if it is within an opening parentheses "(" and to stop looking if find "%)" The way mine is working is that it may sometimes delete everything from a semicolon in regular text to %). Oops.

One problem is that the phrases are not always the same length. The other is that sometimes a comma is used and sometimes a semicolon.

I have text within parentheses that I want to find and only keep "(" up to the ";" or "," and then delete from to "%)"

Another way to do it, I think, could be from within parentheses - any phrase after ; or , that contains ">" or "<"

Example: I want to delete everything after the semicolon through "%)"

(VCI = 106, PR = 66, Average range, CI = 98-113; VCI > MIS, BR = <=15%) To:
(VCI = 106, PR = 66, Average range, CI = 98-113)
------

I also want to completely delete the phrase below. From "(" to ")"
(VCI > WMI, BR = 21.6%; VCI > PSI, BR = 1.7%)


Thing that I want to keep the same:
(SI = 11; VC = 11)
(SI = 11, VC = 10)
(SI = 8, VC = 8)
(IN = 7)

Another problem is that there are different abbreviations (2 or 3), numbers can have a length of 1, 2, 3, or 4, BR =<= can be different (but always include < or >

I'm not if this makes sense. I'm uploading a document. I'm not pasting code I've tried since it all failed in some way and there are about 50 atttempts.

Thank you so much!

Btw, I am a school psychologist working for a single psychologist. Deleting all of the above from reports takes forever and insurance does not cover much that I do. "Boss" is my husband...

-Ashley

macropod
08-28-2022, 03:50 PM
All you need for the first problem is a wildcard Find/Replace, where:
Find = (\(VCI = [!\(]@);[!\(]@\)
Replace = \1)

All you need for the second problem is a wildcard Find/Replace, where:
Find = \(VCI > [!\(]@\)
Replace = nothing

AshZM
08-30-2022, 10:55 AM
OMG, thank you SO much!! Forgot about wildcards! Actually, I do not know enough about them and will get on that.

Can you help with one more? I've been trying, but need to work at some point before my husband fires me, lol.

I have a lot of (WMI > PSI, BR = 20%), and (WMI < PSI, BR = <=5%) that I need to deal with.

I'd like some way to delete the entire thing ( to ) IF BR ≤10%. I do not need to keep any that are ≥10% although I may change to ≥15 sometimes.

BR uses = or =<= or =>= or < or >
I can easily change those to ≥ or ≤ if that helps...
Maybe there could be 3 different ones?

Again, thank you so much! If you're ever in Phoenix, I'll take you out to eat!

-Ashley

macropod
08-30-2022, 03:19 PM
For a Find expression, BR ≤10% is not the same as BR = <=10%. Which are you dealing with, and does it matter what the value after the ≤ or = <= might be?

AshZM
08-30-2022, 04:23 PM
Hi, I am dealing with BR = <=10%. Yes, it does matter what the value is - but really, I can make it less complicated - skip below and see the last line of this message.*

(WMI < FRI, BR = 12.1%). - if the number is under 11, I'd like to keep that whole statement. If it is over 10.99, I'd like to delete that whole statement. They are always in parentheses and if there are more than two, they are separated by a semi-colon

For example - (WMI < VCI, BR = 21.6%; WMI < VSI, BR = 10.5%). In that, I'd like to delete the one with 21.6% and keep the one with 10.5%.
So, the final would like like (WMI<VSI, BR = 10.5%).

That seems like too much to ask. But, maybe you like a challenge (if this even is one) and are bored.

*Just knowing how to delete anything in parentheses containing < or > would be awesome. Maybe you can just help me with that?

Again, thank you!
-Ashley

macropod
08-30-2022, 08:51 PM
So now it seems you have decimal values AND parentheses with more than one BR instance. Are the BRs always decimals? All you mentioned before is single BR instances and whole percentages without decimal points.

As for deleting anything in parentheses containing < or >, all you need is a wildcard Find/Replace, where:
Find = \([!\(]@[\<\>][!\(]@\)
Replace = nothing

AshZM
08-30-2022, 08:58 PM
I forgot how picky coding is. Yes, there are always decimals... Forget about that request...

How about just finding and deleting anything with < or > within ().

That would be great!
Thanks,
-Ashley

macropod
08-30-2022, 09:21 PM
To delete the first set of expressions between parentheses where a semi-colon is present, all you need is a wildcard Find/Replace where:
Find = \([!\(]@\;^32
Replace = (

To delete parentheses and the expressions between where the first BR instance has a value less than 10, all you need is a wildcard Find/Replace where:
Find = \([!\(]@BR[\<\= ]@[0-9].*\)
Replace = nothing

To delete parentheses and the expressions between where the first BR instance has a value between 10 and 11, all you need is a wildcard Find/Replace where:
Find = \([!\(]@BR[\<\= ]@10.*\)
Replace = nothing

AshZM
08-31-2022, 01:15 PM
Thank you so much. I really appreciate your help!

-Ashley