How to Remove Brackets From a String in VBA

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Email

As a computer programmer, you may need to replace characters in a string variable in your VBA applications. In VBA, you can use the "Replace" function to replace a character or set of characters rather than writing code to loop through every character in your string. The "Replace" function returns a string in which it replaces a specified substring with another substring.

Skill level:
Moderately Easy

Other People Are Reading


  1. 1

    Launch Microsoft Office Excel, click the "Developer" tab and click "Visual Basic."

  2. 2

    Click the "Insert" field and click "Module" to insert a new module.

  3. 3

    Type the following to create a new sub procedure:

    Private Sub remove Brackets()

  4. 4

    Add the following code to create a string variable to hold a string with brackets:

    Dim tempStr As String

    tempStr = "[brackets have been removed]"

  5. 5

    Type the following code to remove the brackets from the string:

    tempStr = Replace(tempStr, "[", "")

    tempStr = Replace(tempStr, "]", "")

  6. 6

    Add the following line to display the string using a message box:

    MsgBox (tempStr)

  7. 7

    Type "End Sub" to end the procedure.

  8. 8

    Press "F5" to run.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.