+ Reply to Thread
Results 1 to 7 of 7

Thread: Replacing 2+ consecutive characters

  1. #1
    Registered User
    Join Date
    12-13-2011
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    11

    Replacing 2+ consecutive characters

    Hi and thanks in advance!

    I'm hoping this will be simple and I'm just overlooking something obvious. I have a cell containing the following text...**the string of hyphens are representing multiple spaces for this example. My preview indicated the multiple spaces would not show up once posted**

    ------ALL CAPS TOGETHER----- all lower case together--- finally this one---------


    This above is all in one cell - we'll say A2. My sheet contains several hundred cells that mimic this pattern...the cells start with a string of spaces (again, represented by the dash marks), then there are phrases separated by undetermined amount of space groups in the middle (varying number of phrases and spaces cell to cell), and end with yet even more spaces.

    Using just the example above, what I want to end up with for this cell is:

    ALL CAPS TOGETHER, all lower case together, finally this one


    So I'll have replaced anywhere there are two or more consecutive spaces with ", " and removed the beginning and end space altogether. Can anyone help? THANK YOU
    Last edited by PennyKat; 12-14-2011 at 06:04 PM.

  2. #2
    Registered User
    Join Date
    06-06-2011
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2007
    Posts
    23

    Re: Please help - replacing 2+ consecutive characters

    Hi,
    If they are all in one column, you can do this:
    Do "Text to columns" in the data tab, seperate all of the information into 3 seperate cells, then in cell d2 put =concatanate(a2,b2,c2).
    I haven't tried, so save before you try it yourself.
    Good luck.

  3. #3
    Forum Contributor
    Join Date
    06-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    117

    Re: Please help - replacing 2+ consecutive characters

    Make a separate worksheet.
    In there, type in A1:
    =TRIM(Sheet1!A1)

    Then fill rows and columns with it.

    This will remove all excess spaces from start, middle and end of cells. It would give you:
    ALL CAPS TOGETHER all lower case together finally this one

    Without the commas unfortunately.

    Then save and export as a txt csv. Import that into excel using the import wizard and specify commas as deliminators.

  4. #4
    Registered User
    Join Date
    12-13-2011
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Please help - replacing 2+ consecutive characters

    Thanks aldek, but unfortunately I have an undetermined number of phrases per cell. Some of them are in the hundreds so manually typing them in is what I want to avoid. The example I gave was just that, an example

    dip11, thanks that's more in the right direction. Unfortunately the same as above applies. For me to comma delimit all phrases would be extremely daunting.

    I appreciate the help though!

  5. #5
    Forum Contributor
    Join Date
    06-10-2011
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    117

    Re: Replacing 2+ consecutive characters

    Comma delimiting would be automatic, like a tickbox. You wouldn't have to select every single phrase.

  6. #6
    Registered User
    Join Date
    12-13-2011
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Replacing 2+ consecutive characters

    My problem I think is that It's separating each word when I use delimited instead of only separating phrases. Each row has a different number of phrases at different lengths.. I also can't use the fixed width when importing. Also, you mentioned above to specify commas as the delimiter, but the saved txt csv you reference doesn't have commas.

  7. #7
    Registered User
    Join Date
    12-13-2011
    Location
    Denver, Colorado
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Replacing 2+ consecutive characters

    I've figured out what I needed to do. This is the code that ended up working great for me and my needs on this project...

    Function ConcatRange(rCat As Range) As String
        Dim cell        As Range
        Dim rInt        As Range
    
        Set rInt = Intersect(rCat.Worksheet.UsedRange, rCat)
        If Not rInt Is Nothing Then
            For Each cell In rInt
                If Len(cell.Text) Then
                    ConcatRange = ConcatRange & cell.Text & " "
                Else
                    If Right(ConcatRange, 1) <> "/" Then ConcatRange = ConcatRange & "/"
                End If
            Next cell
        End If
        
        If Left(ConcatRange, 1) = "/" Then ConcatRange = Mid(ConcatRange, 2)
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0