+ Reply to Thread
Results 1 to 2 of 2

Insert Spaces

  1. #1
    Ronbo
    Guest

    Insert Spaces

    I need to know how to insert spaces at given positions in a string.
    There are 27 characters (positions) and it would go as follows;

    111223333334445566666666666

    Changed to;
    111 22 333333 444 55

    Dim tmpName2 As String
    tmpName2 = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 11)

    The first statements removes the last 11 characters and leaves
    1112233333344455

    What I need is the syntax to insert the spaces in the name at position 4, 7
    14 and 18.



  2. #2
    Bob Phillips
    Guest

    Re: Insert Spaces

    sVal = "111223333334445566666666666"
    ary = Array(4, 7, 14, 18)

    For i = LBound(ary) To UBound(ary)
    sVal = Left(sVal, ary(i) - 1) & " " & Right(sVal, Len(sVal) - ary(i)
    + 1)
    Next i

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Ronbo" <[email protected]> wrote in message
    news:[email protected]...
    > I need to know how to insert spaces at given positions in a string.
    > There are 27 characters (positions) and it would go as follows;
    >
    > 111223333334445566666666666
    >
    > Changed to;
    > 111 22 333333 444 55
    >
    > Dim tmpName2 As String
    > tmpName2 = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 11)
    >
    > The first statements removes the last 11 characters and leaves
    > 1112233333344455
    >
    > What I need is the syntax to insert the spaces in the name at position 4,

    7
    > 14 and 18.
    >
    >




+ 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