This tutorial demonstrates how to replace a space character with an underscore in Excel and Google Sheets.
Replace Space With Underscore
In Excel, you can easily replace spaces with underscores. Say you have product names with product and manufacturer separated by spaces (as shown below), and you want to separate them by underscores instead.
- Select the range of cells where you want to replace spaces (here, B2:B7), and in the Ribbon, go to Home > Find & Select > Replace (or use the keyboard shortcut CTRL + H).
- In the Find and Replace window, (1) type a space in Find what box and (2) underscore (_) in the Replace with box. Then (3) click on Replace All.
- A message pops up with the total number of changes made; just press OK.
- Close the Find and Replace window by clicking on the Close button.
As a result, all spaces in the selected cells are replaced by underscores.
Replace Space With Underscore in Google Sheets
You can replace spaces with underscores in Google Sheets in a very similar way.
- Select the range of cells where you want to replace spaces (B2:B7), and in the Menu, go to Edit > Find and replace (or use the keyboard shortcut CTRL + H).
- In the pop-up window, (1) enter space in the Find box and (2) underscore (_) in the Replace with box. The, (3) click Replace All and (4) Done.
The result is the same as in Excel: All spaces in the selected range are converted to underscores.