VBA: loop in cells and delete bracket content

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
525
Office Version
  1. 2007
Hello everybody.

I'm looping in a range:
Code:
For Each cell In Sheets(2).Range("F2:F" & lr3)
   '....
Next cell

For each cell in this range, I need, if existent brackets with exactly 2 characters as a content, delete the brackets and its content.

For example:

Code:
LONDON (LD)
has to be turned into
Code:
LONDON
Code:
BERLIN (BL) GERMANY
has to be turned into
Code:
BERLIN GERMANY

But
Code:
ROME (ITALY)
has to stay unchanged because of 5 charachters and not 2 into the brackets.


Can you support me?

Thank's.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
No need for a loop, you can do it like
Code:
  Sheets(2).Range("F2:F" & LR3).Replace "(??)", "", xlPart, , , , False, False
 
Upvote 0
If you always have a space before & after the brackets, use this instead.
Code:
  Sheets(2).Range("F2:F" & LR3).Replace " (??)", "", xlPart, , , , False, False
 
Upvote 0
For the cells in question, are the only values the city and the bracketed information? Or, is there other information in the cells also. Can you provide a sample of 5-10 cell values showing all possible type of combinations so that we can provide a viable solution.
 
Upvote 0

Forum statistics

Threads
1,213,539
Messages
6,114,221
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top