+ Reply to Thread
Results 1 to 6 of 6

Delimiting without truncating

Hybrid View

  1. #1
    Registered User
    Join Date
    05-21-2009
    Location
    Portland US
    MS-Off Ver
    Excel 2007
    Posts
    14

    Delimiting without truncating

    I have an address file containing a few hundered thousand rows of data.
    The max character lines for my lables is 60 and unfortunatly a large number of the fields exceed this limit.
    I need to create a string somthing to the effect of:

    delimination
    if len(A2<60) end
    if len(A2>60) then
    if character 60 isblank then deliminate = 60
    if character 60 not isblank then deliminate at blank < 60

    It makes more sence in my head.

    Any suggestions?
    Last edited by sirlink; 05-22-2009 at 01:52 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Delimiting without truncating

    Maybe like this:
    Sub x()
        Dim cell    As Range
        
        For Each cell In Selection
            With cell
                If Len(.Text) > 60 Then .Value = Left(.Text, InStrRev(.Text, " ", 60) - 1)
            End With
        Next cell
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-21-2009
    Location
    Portland US
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Delimiting without truncating

    That is almost perfect. I need to preserve the information
    IE
    Colmn A
    "WEINBERG, GRIFFITH, TUCKER AND JONES PA., PROFIT SHARING PLANAND TRUST - DTD 12/21/87"

    Would be

    Colmn A
    "WEINBERG, GRIFFITH, TUCKER AND JONES PA., PROFIT SHARING"
    Column B
    "PLANAND TRUST - DTD 12/21/87"

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Delimiting without truncating

    Try this:
    Sub x()
        Dim r       As Range
        Dim cell    As Range
        Dim iPos    As Long
    
        Set r = Selection
        If r.Columns.Count > 1 Then
            MsgBox "Single column selection only"
    
        Else
            For Each cell In r
                With cell
                    If Len(.Text) > 60 Then
                        iPos = InStrRev(.Text, " ", 60)
                        .Offset(, 1).Value = Mid(.Text, iPos + 1)
                        If iPos > 0 Then
                            .Value = Left(.Text, iPos - 1)
                        Else
                            .ClearContents
                        End If
                    End If
                End With
            Next cell
        End If
    End Sub
    Last edited by shg; 05-22-2009 at 12:18 PM.

  5. #5
    Registered User
    Join Date
    05-21-2009
    Location
    Portland US
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Delimiting without truncating

    Perfection!!!

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Delimiting without truncating

    You're welcome. Would you please mark the thread as Solved?

+ 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