VBA: loop in cells and delete bracket content

Nelson78

Active Member
Joined
Sep 11, 2017
Messages
480
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.
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
No need for a loop, you can do it like
Code:
  Sheets(2).Range("F2:F" & LR3).Replace "(??)", "", xlPart, , , , False, False
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,301
Office Version
  1. 365
Platform
  1. Windows
If you always have a space before & after the brackets, use this instead.
Code:
  Sheets(2).Range("F2:F" & LR3).Replace " (??)", "", xlPart, , , , False, False
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
6,069
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,311
Messages
5,600,886
Members
414,414
Latest member
neil_c

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
Top