If you want to change all spaces for underscores use:

=SUBSTITUTE(C8," ","_")

To remove multiple spaces at the start or end of your string, use:

=SUBSTITUTE(TRIM(C8)," ","_")
Answer from cybernetic.nomad on Stack Exchange
🌐
Reddit
reddit.com › r/excel › adding a leading underscore
r/excel on Reddit: Adding a leading underscore
February 2, 2023 -

I'm trying to make a dependent drop down list from a main list that is something like:

  • 1A

  • 1B

  • 2A

  • 2M

  • XYZ

  • Alpha

  • 7

  • 13

  • 21

I see that the named ranges that begin with numbers adds an underscore as the first character and that's screwing up my =INDIRECT() equation for the range of the dependent list. (It's working fine if I use a subset of just XYZ and Alpha)

How so I tell Excel to add a leading underscore? Everything I can google it talking about substituting an underscore in between things, and not adding a leading one.

Discussions

Need excel formula to insert underscore before the Proper case letter where ever find it in a string.
I need to replace a string like below: IpArId to be converted as Ip_Ar_Id Wherever the upper cases identified in a string to be prefixed with "underscore" ("_"). More on mrexcel.com
🌐 mrexcel.com
3
0
May 27, 2018
vba - "_" underscore in Excel Formula - Stack Overflow
I'm getting a problem, when I try to run these commands. Problem come from the formula expresion, since "_" is a syntax error, but I need exactly that formula in my Excel cells, How could I solve ... More on stackoverflow.com
🌐 stackoverflow.com
Underscore between words
Is there a way to (macro) insert an underscore between all spaced words in say column d? before: top of the world after: top_of_the_world Thanks! More on mrexcel.com
🌐 mrexcel.com
4
0
June 9, 2009
Formula to add underscore where spaces exist? | Chandoo.org Excel Forums - Become Awesome in Excel
See attached. I'm looking for a formula that will automatically look at the cell to the left and add in an underscore where appropriate. Any ideas? More on chandoo.org
🌐 chandoo.org
December 9, 2014
🌐
Quora
quora.com › How-do-you-insert-an-underscore-in-Excel
How to insert an underscore in Excel - Quora
Answer (1 of 2): The question is ambiguous. First possible answer is “Write it from the keyboard and close the cell” Second possible answer may understand the need of changing spaces and replace them by underscores in a selected area. This time you should use the dialog “Find and replace”, ...
🌐
MrExcel
mrexcel.com › forums › question forums › excel questions
Need excel formula to insert underscore before the Proper case letter where ever find it in a string. | MrExcel Message Board
May 27, 2018 - Function Underscore(s As String) As String Static RX As Object If RX Is Nothing Then Set RX = CreateObject("VBScript.RegExp") RX.Global = True End If RX.Pattern = "([A-Z])" Underscore = s If RX.Test(s) Then Underscore = Left(s, 1) & RX.Replace(Mid(s, 2), "_$1") End Function ... An alternative would be .. ... Function Under_Score(s As String) As String Dim i As Long For i = Len(s) To 2 Step -1 If Mid(s, i, 1) Like "[A-Z]" Then s = Left(s, i - 1) & "_" & Mid(s, i) Next i Under_Score = s End Function ... You must log in or register to reply here. ... I need a formula to separate Christian names from surnames when joined together in a name in a text cell e.g.
🌐
Excel Forum
excelforum.com › excel-new-users-basics › 670293-add-underscore-in-between-letter-and-number.html
Thread: add underscore in between letter and number
Thanks for fixing the title... are the consistently 2-digits, underscore, 1 or more letters... If yes, try =REPLACE(A1,3,0,"_") where A1 contains first item to change... You can then copy|Paste Special >> Values over original if desired. ... This kind of works but not really it will require me to change the formula for each cell, when I copy and paste special it just ends up 01_A 01_A 01_A 01_A 01_A yes there will be two digits they run in sets 01A-D, 02A-D.....
🌐
Avantix Learning
avantixlearning.ca › home › how to replace spaces in excel with underscores (_), dashes (-) or other values
How to Replace Spaces in Excel with Underscores (_), Dashes (-) or Other Values
April 13, 2022 - In the Replace with box, type an underscore, dash, or other value. If you want to replace the space with nothing, leave the box blank. Click Replace All. A dialog box appears indicating the number of replacements. ... You can also create a formula and use the SUBSTITUTE function to replace spaces in text strings.
Find elsewhere
🌐
MyExcelOnline
myexcelonline.com › home › how to use the underscore symbol in excel
How to Use the Underscore Symbol in Excel | MyExcelOnline
June 16, 2025 - Underscores are used to replace spaces in Excel names to avoid formula errors. They help create clean, readable named ranges like Total_Sales_2024. VBA macros require underscores because spaces aren’t allowed in variable or function names. In file exports, underscores prevent naming issues during uploads or automation. In custom number formatting, underscores add ...
🌐
The Bricks
thebricks.com › home › resources › how to replace spaces with underscores in excel
How to Replace Spaces with Underscores in Excel - Bricks
February 12, 2025 - This formula tells Excel to look at cell A2, find every space character (" "), and replace each one with an underscore ("_").
🌐
Earn and Excel
earnandexcel.com › home › blog › how to add underscore between words in excel
How to Add Underscore between Words In Excel - Earn and Excel
August 6, 2024 - Start by opening the Excel file where you need to add underscores. Highlight the cells containing the text that you want to modify. Press `Ctrl+H` to open the Find and Replace dialog box. In the “Find what” field, enter a space ( ). In the “Replace with” field, enter an underscore (_). 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. If you prefer using formulas, the SUBSTITUTE function in Excel can be very effective.
🌐
Automate Excel
automateexcel.com › home › replace space with underscore in excel & google sheets
Replace Space With Underscore in Excel & Google Sheets - Automate Excel
February 27, 2023 - 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.
🌐
Excelcommand
excelcommand.com › excel-help › excel-how-to.php
Excel - Add Underscore In Between Letter And Number - I dont know... - Free Excel Help
AS=2, AM=7, etc.)? In previous years I made a column for each size, and simply placed a "1" in the correct column, and had excel just add the 1's from each column. However, that takes more time and space. I was hoping to streamline it this time around. Thanks for taking the time to read this post. Any help would be appreciated! Thanks, doug · This formula should be very often to use, but i cant found it anywhere, so i ask this here For example in a1 is : mike is playing basketball, he is very great player i want to make it in b1 to be uppercase only in first letter so : Mike is playing basketball, he is very great player i know about proper formula =proper(a1) , but proper formula is make uppercase to all first letter in all words, we just need first letter in first words to be uppercase (and to every first words after dot if it can)
🌐
Statology
statology.org › home › how to replace space with underscore in excel
How to Replace Space with Underscore in Excel
August 17, 2023 - Then type Ctrl + H to bring up the Find and Replace feature in Excel. Then type a single space in the Find what box and type a single underscore in the Replace with box.
🌐
YouTube
youtube.com › office expert
Add Underscore in Excel for Beginners | Step-by-Step Tutorial & Tips - YouTube
Welcome to our step-by-step tutorial on how to add underscores in Excel! Whether you're a beginner or just looking to enhance your skills, this video will gu...
Published: September 25, 2024
Views: 571
🌐
Arab Psychology
scales.arabpsychology.com › home › replace space with underscore in excel
Replace Space With Underscore In Excel
November 18, 2025 - To address issues of excessive or inconsistent spacing before applying the underscore transformation, the TRIM function is an indispensable precursor. The TRIM function removes all leading, trailing, and redundant multiple spaces, ensuring only single spaces remain between words. By nesting the SUBSTITUTE function within the TRIM function, we can create a powerful, two-step cleaning solution. The combined formula would look like this: =SUBSTITUTE(TRIM(A2), ” “, “_”).
🌐
YouTube
youtube.com › skills up academy
Skills Up Academy | How to add underscore | Excel Tips & Tricks | ExcelTutorial - YouTube
In this informative video by Skills Up Academy, we delve into one of the most overlooked yet essential skills in Excel—how to add an underscore. Whether you'...
Published: January 21, 2025
Views: 54
🌐
MrExcel
mrexcel.com › forums › question forums › excel questions
Underscore between words | MrExcel Message Board
June 9, 2009 - Sub underscore() For Each cell In Range(Cells(1, "D"), Cells(Cells(Rows.Count, "D").End(xlUp).Row, "D")) cell.Value = replace(cell.Value, " ", "_") Next cell End Sub ... That's it!!
🌐
Microsoft Answers
answers.microsoft.com › en-us › msoffice › forum › all › how-to-format-a-character-in-a-cell-value › b680f2e8-188a-4004-8536-f3a1302aa925
How to format a character ("_") in a cell value. - Microsoft Q&A
November 25, 2019 - I created a workbook where you enter an item number (1-3) on sheet1 in A1, and it populates the size in A2 by looking up the value in a table on sheet2 that looks like below. However, when I enter an item number and the size populates on sheet1, the underscore is still visible, and it doesn't appear that the code even runs. ... Thanks again! ... If you are using formulas, then the code needs to convert the formula to values.
🌐
YouTube
youtube.com › watch
Replace Spaces with a Dash or Underscore in Excel (3 Ways) - YouTube
Video outlines 3 ways to replace spaces with a dash or underscore in Excel. Methods covered include find and replace, the SUBSTITUTE function, and flash fill...
Published: August 25, 2022