Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 24 of 24

Thread: Solved: insert space in a string after n characters

  1. #21
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps

    [VBA]Sub test()
    Call InsertTextEveryN(Range("A1"), 4, " ")
    End Sub

    Sub InsertTextEveryN(aRange As Range, everyN As Long, insertedText As String)
    Dim LOfText As Long
    Dim i As Long
    LOfText = Len(CStr((aRange.Cells(1, 1).Value)))
    For i = Application.Floor(LOfText, everyN) + 1 To 2 Step -everyN
    aRange.Cells(1,1).Characters(i, 0).Insert (insertedText)
    Next i
    End Sub
    [/VBA]

  2. #22

    copy a color of conditionally formatted cell

    sorry, mistake

  3. #23
    GTO

    Thanks for the code. it works a charm.

  4. #24
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    You are most welcome and glad it worked

Posting Permissions

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