Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Oct 2005
    Location
    Cambridgeshire, USA
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Text in cell to undescore (2003)

    Hello Everyone,

    I have a bunch of cells that have text in them. I will be running a list and indirect functions from it. How do can I format a cell so that everytime there is a space to put and underscore. For example, a A1 says "Testing Mode" I want to format to say Testing_Mode". Any help would be great.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Text in cell to undescore (2003)

    I don't think there is a cell format that replaces spaces with underscores. You can use a formula:
    <code>
    =SUBSTITUTE(A1," ","_")
    </code>
    It would also be possible to replace spaces with underscores when the user enters or edits a value: right-click the sheet tab and select View Code. Paste the following code into the module:
    <code>
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim oCell As Range
    Application.EnableEvents = False
    For Each oCell In Target.Cells
    If Not oCell.HasFormula Then
    oCell = Replace(oCell, " ", "_")
    End If
    Next oCell
    Application.EnableEvents = True
    End Sub</code>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •