How to Add Underscore between Words In Excel

  • Home
  • / How to Add Underscore between Words In Excel
How to Add Underscore between Words In Excel

Microsoft Excel is a powerful tool for managing and manipulating data. Whether you are working with large datasets, performing complex calculations, or simply organizing information, Excel offers a plethora of functions and features to streamline your workflow.One common task that users often encounter is the need to format text data in specific ways. A frequent requirement is adding underscores between words in a text string, particularly for creating file names, database entries, or standardized text formats.This guide will walk through the significance of how to add underscore between words in excel, and a step-by-step process to use it in Excel.

Significance of Adding Underscores

The significance of adding underscores between words in Excel lies in its practical applications across various fields:

  1. File Naming Conventions:

Underscores are often used in file names to separate words, ensuring the file name is readable and without spaces, which are not allowed in some systems.

  1. Database Management:

Databases often require entries without spaces, and underscores serve as a clear delimiter between words.

  1. Coding and Programming:

In programming, variable names and function names often use underscores to separate words for readability.

  1. Text Standardization:

Standardizing text formats across large datasets helps in maintaining consistency, especially when preparing data for import into other applications or systems.

Step-by-Step Process to Add Underscores Between Words in Excel

There are several methods to add underscores between words in Excel, ranging from simple manual methods to more complex formula-based approaches. Here’s a detailed guide on how to achieve this:

Method 1: Using the Replace Function

  1. Open Your Excel File:

Start by opening the Excel file where you need to add underscores.

  1. Select the Cells:

Highlight the cells containing the text that you want to modify.

  1. Open Find and Replace:

Press `Ctrl+H` to open the Find and Replace dialog box.

  1. Find and Replace:

    In the “Find what” field, enter a space ( ).

    In the “Replace with” field, enter an underscore (_).

  1. Replace All:

Click on “Replace All”. Excel will replace all spaces in the selected cells with underscores.

This method is straightforward and works well for simple replacements.

Method 2: Using Formulas

If you prefer using formulas, the SUBSTITUTE function in Excel can be very effective.

  1. Open Your Excel File:

Open the Excel file containing the text.

  1. Select a Cell for the Formula:

Choose a cell where you want to display the modified text.

  1. Enter the Formula:

    Use the SUBSTITUTE function: `=SUBSTITUTE(A1, ” “, “_”)`

    Replace `A1` with the reference to the cell containing your text.

  1. Apply the Formula:

Press `Enter`. The cell will now display the text from cell `A1` with spaces replaced by underscores.

  1. Copy the Formula:

Drag the fill handle to apply the formula to other cells if needed.

The SUBSTITUTE function is highly versatile and can be used within more complex formulas for additional processing.

Method 3: Using VBA (Visual Basic for Applications)

For more advanced users, VBA can be used to automate the process:

  1. Open the VBA Editor:

Press `Alt+F11` to open the VBA editor.

  1. Insert a New Module:

Click on `Insert` > `Module`.

  1. Enter the VBA Code:

  2. Run the Macro:

Close the VBA editor, select the cells you want to modify, and run the macro by pressing `Alt+F8`, selecting `ReplaceSpacesWithUnderscores`, and clicking `Run`.

This VBA script will replace spaces with underscores in the selected cells, providing a powerful way to automate the process.

Pros and Cons of Each Method

Replace Function


Quick and easy to use.

No need for formulas or coding knowledge.

Ideal for one-time or simple tasks.


– Not dynamic; changes are not automatically updated if the original text changes.

– Limited to straightforward replacements.

Using Formulas


Dynamic and updates automatically when the original text changes.

Can be incorporated into more complex formulas.

No need to manually trigger changes.


Requires understanding of Excel functions.

Can be cumbersome for large datasets if not properly managed.

Using VBA


Highly customizable and can automate complex tasks.

Ideal for repetitive tasks and large datasets.

Can handle a wide range of text manipulation requirements.


Requires knowledge of VBA programming.

Potentially risky if not properly tested, as it can alter large amounts of data quickly.

Not as accessible for users unfamiliar with programming.


  • Adding underscores between words in Excel is a common requirement with various applications in file naming, database management, programming, and data standardization. Each method whether using the Replace function, formulas, or VBA—offers unique advantages and suits different levels of complexity and user expertise.
  • For simple, one-off tasks, the Replace function is quick and efficient. For dynamic, ongoing updates, formulas provide a robust solution. For large-scale or repetitive tasks, VBA offers powerful automation capabilities.
  • By understanding and utilizing these methods of how to add underscore between words in excel, Excel users can significantly enhance their data manipulation capabilities, ensuring their text data is formatted correctly and efficiently for their specific needs.

Write your comment Here