+ Reply to Thread
Results 1 to 5 of 5

Remove space and "-" character

  1. #1
    Registered User
    Join Date
    01-15-2006
    Posts
    24

    Remove space and "-" character

    Dear All,

    Could you help me to remove space and "-" in cell's value?
    Ex : 123 456 - 789 = 123456789

    Thanks

    Thanh Nguyen

  2. #2
    NickHK
    Guest

    Re: Remove space and "-" character

    One way:
    Range("A1").Text=Replace(Range("A1").Text, " - ","")
    combined with .Find or loop through cells.

    NickHK

    "thanhnguyen" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Dear All,
    >
    > Could you help me to remove space and "-" in cell's value?
    > Ex : 123 456 - 789 = 123456789
    >
    > Thanks
    >
    > Thanh Nguyen
    >
    >
    > --
    > thanhnguyen
    > ------------------------------------------------------------------------
    > thanhnguyen's Profile:

    http://www.excelforum.com/member.php...o&userid=30502
    > View this thread: http://www.excelforum.com/showthread...hreadid=558287
    >




  3. #3
    Tim Marsh
    Guest

    Re: Remove space and "-" character

    if you want it to apply to the whole sheet, its probably just as easy to use
    Edit > Replace... from the menu bar, eg, find "-" (without quotes) and
    replace with nothing, then do teh same for the "space"



    "thanhnguyen" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Dear All,
    >
    > Could you help me to remove space and "-" in cell's value?
    > Ex : 123 456 - 789 = 123456789
    >
    > Thanks
    >
    > Thanh Nguyen
    >
    >
    > --
    > thanhnguyen
    > ------------------------------------------------------------------------
    > thanhnguyen's Profile:
    > http://www.excelforum.com/member.php...o&userid=30502
    > View this thread: http://www.excelforum.com/showthread...hreadid=558287
    >




  4. #4
    Registered User
    Join Date
    01-15-2006
    Posts
    24

    Re: Replace and TrimSpace function

    Hello,

    I found this function on MSDN

    Function ReplaceWord(strText As String, _
    strFind As String, _
    strReplace As String) As String

    ' This function searches a string for a word and replaces it.
    ' You can use a wildcard mask to specify the search string.

    Dim astrText() As String
    Dim lngCount As Long

    ' Split the string at specified delimiter.
    astrText = Split(strText)

    ' Loop through array, performing comparison
    ' against wildcard mask.
    For lngCount = LBound(astrText) To UBound(astrText)
    If astrText(lngCount) Like strFind Then
    ' If array element satisfies wildcard search,
    ' replace it.
    astrText(lngCount) = strReplace
    End If
    Next
    ' Join string, using same delimiter.
    ReplaceWord = Join(astrText)
    End Function

    This function can replace "-" character but space can not. I also found the function TrimSpace which remove extra spaces from a string:

    Function TrimSpace(strInput As String) As String
    ' This procedure trims extra space from any part of
    ' a string.

    Dim astrInput() As String
    Dim astrText() As String
    Dim strElement As String
    Dim lngCount As Long
    Dim lngIncr As Long

    ' Split passed-in string.
    astrInput = Split(strInput)

    ' Resize second array to be same size.
    ReDim astrText(UBound(astrInput))

    ' Initialize counter variable for second array.
    lngIncr = LBound(astrInput)
    ' Loop through split array, looking for
    ' non-zero-length strings.
    For lngCount = LBound(astrInput) To UBound(astrInput)
    strElement = astrInput(lngCount)
    If Len(strElement) > 0 Then
    ' Store in second array.
    astrText(lngIncr) = strElement
    lngIncr = lngIncr + 1
    End If
    Next
    ' Resize new array.
    ReDim Preserve astrText(LBound(astrText) To lngIncr - 1)

    ' Join new array to return string.
    TrimSpace = Join(astrText)
    End Function


    but still not solve my problem, please give me any advice.
    Thanks

    Thanh Nguyen

  5. #5
    NickHK
    Guest

    Re: Remove space and "-" character

    Did you read the replies you have received ?

    NickHK

    "thanhnguyen" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Hello,
    >
    > I found this function on MSDN
    >
    > Function ReplaceWord(strText As String, _
    > strFind As String, _
    > strReplace As String) As String
    >
    > ' This function searches a string for a word and replaces it.
    > ' You can use a wildcard mask to specify the search string.
    >
    > Dim astrText() As String
    > Dim lngCount As Long
    >
    > ' Split the string at specified delimiter.
    > astrText = Split(strText)
    >
    > ' Loop through array, performing comparison
    > ' against wildcard mask.
    > For lngCount = LBound(astrText) To UBound(astrText)
    > If astrText(lngCount) Like strFind Then
    > ' If array element satisfies wildcard search,
    > ' replace it.
    > astrText(lngCount) = strReplace
    > End If
    > Next
    > ' Join string, using same delimiter.
    > ReplaceWord = Join(astrText)
    > End Function
    >
    > This function can replace "-" character but space can not. I also found
    > the function TrimSpace which remove extra spaces from a string:
    >
    > Function TrimSpace(strInput As String) As String
    > ' This procedure trims extra space from any part of
    > ' a string.
    >
    > Dim astrInput() As String
    > Dim astrText() As String
    > Dim strElement As String
    > Dim lngCount As Long
    > Dim lngIncr As Long
    >
    > ' Split passed-in string.
    > astrInput = Split(strInput)
    >
    > ' Resize second array to be same size.
    > ReDim astrText(UBound(astrInput))
    >
    > ' Initialize counter variable for second array.
    > lngIncr = LBound(astrInput)
    > ' Loop through split array, looking for
    > ' non-zero-length strings.
    > For lngCount = LBound(astrInput) To UBound(astrInput)
    > strElement = astrInput(lngCount)
    > If Len(strElement) > 0 Then
    > ' Store in second array.
    > astrText(lngIncr) = strElement
    > lngIncr = lngIncr + 1
    > End If
    > Next
    > ' Resize new array.
    > ReDim Preserve astrText(LBound(astrText) To lngIncr - 1)
    >
    > ' Join new array to return string.
    > TrimSpace = Join(astrText)
    > End Function
    >
    >
    > but still not solve my problem, please give me any advice.
    > Thanks
    >
    > Thanh Nguyen
    >
    >
    > --
    > thanhnguyen
    > ------------------------------------------------------------------------
    > thanhnguyen's Profile:

    http://www.excelforum.com/member.php...o&userid=30502
    > View this thread: http://www.excelforum.com/showthread...hreadid=558287
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1