Sometimes we need to add brackets into cells to enclose texts for some reasons. If we only add brackets for one single cell, it is very easy, but if there are a column of cells need to add brackets, how can we do? This article will show you three simple ways to add brackets by Formula, Format Cells Function and VBA code.
In condition, we prepare a table to save Year.
We use this sample to do demonstration.
Add Brackets for Cells by Formula in Excel
Step 1: Select another column for example column B, in cell B2 enter =”(“&A2&”)”.
Step 2: Press Enter to get result.
Step 3: Select cell B2 which contains the formula, drag it and fill the cells B3 and B4. Then we can get a new column with brackets enclose the texts. You can copy the result to cover column A by paste with value.
Add Brackets for Cells by Format Cells Function in Excel
Step 1: Select all ranges you want to add brackets for them. In this case select A2, A3 and A4.
Step 2: Right click your mouse, select ‘Format Cells…’.
Step 3: On Format Cells window, select Custom under Category list.
Step 4: In Type, enter “(“General”)”. Then you can find 2017 is changed to (2017) in Sample.
If the value in cell is Text, you can enter “(“@”)” in type instead.
Step 5: Click OK to get result. All cells are enclosed with brackets properly.
Add Brackets for Cells by VBA Code in Excel
Step1: open your excel workbook and then click on “
Visual Basic” command under
DEVELOPER Tab, or just press “
Step2: then the “
Visual Basic Editor” window will appear.
Step3: click “
Module” to create a new module.
Step4: paste the below VBA code into the code window. Then clicking “
Sub addbrackets() Set myRange = Application.Selection Set myRange = Application.InputBox("please select a Range", "addbrackets", myRange.Address, Type:=8) For Each myCell In myRange myCell.Value = "(" & myCell.Value & ")" Next End Sub
Step5: back to the current worksheet, click on
Macros button under
Code group. then click
Step6: you need to type one password to protect your current worksheet, click on
Step7: you would see that the selected cells have been inserted brackets around text.