Macro to remove Brackets from Column

Alvaroro84

Board Regular
Joined
May 13, 2022
Messages
65
Office Version
  1. 2016
Platform
  1. Windows
I'm often using a data base to download data and this database downloads all numbers like this [1611653651] in multiple columns. I want to create a macro that would help me instantly remove all those brackets. I would use the replace command on excel but I have over 1,000,000 rows so it takes a long time.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The macro won't be any faster. In fact it could be slower. Built-in features are hella fast. Doing anything to a million rows is going to take a while.

VBA Code:
Public Sub RemoveBrackets()

    AcitveSheet.Cells.Replace What:="[", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
        FormulaVersion:=xlReplaceFormula2
    ActiveSheet.Cells.Replace What:="]", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
        FormulaVersion:=xlReplaceFormula2

End Sub
 
Upvote 0
Solution
The macro won't be any faster. In fact it could be slower. Built-in features are hella fast. Doing anything to a million rows is going to take a while.

VBA Code:
Public Sub RemoveBrackets()

    AcitveSheet.Cells.Replace What:="[", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
        FormulaVersion:=xlReplaceFormula2
    ActiveSheet.Cells.Replace What:="]", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
        FormulaVersion:=xlReplaceFormula2

End Sub
Couldn't have said it any better my self Jeff. Thank you for the help!
 
Upvote 0
The macro won't be any faster. In fact it could be slower. Built-in features are hella fast. Doing anything to a million rows is going to take a while.

VBA Code:
Public Sub RemoveBrackets()

    AcitveSheet.Cells.Replace What:="[", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
        FormulaVersion:=xlReplaceFormula2
    ActiveSheet.Cells.Replace What:="]", Replacement:="", LookAt:=xlPart, SearchOrder:= _
        xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False, _
        FormulaVersion:=xlReplaceFormula2

End Sub
I ran it against 1,200,000 rows with 5 full columns full of brackets it ran 7 minutes and works like a charm!
 
Upvote 0
I guess the advantage to the macro is it is only one operation so you can start it, go have a cup of coffee, and it's finished, rather than having to do two separate Find and Replaces.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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