Consulting

Results 1 to 3 of 3

Thread: Solved: add slash in string

  1. #1
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location

    Solved: add slash in string

    hi,

    i have a column of data in which i need to add a slash to separate the alphas from the numerics.i don't need the slash at the beginning or end of the string

    can you help me with a formula or better yet a vba solution?
    please look at the attachment for examples


    thanks
    zach

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Dim NumberFlag As Boolean
    Dim LastRow As Long
    Dim LastChar As Long
    Dim tmp As String
    Dim i As Long, j As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
    For i = 1 To LastRow

    If .Cells(i, "C").Value <> "" Then

    tmp = Mid(.Cells(i, "C").Value, 1, 1)
    NumberFlag = IsNumeric(Mid(.Cells(i, "C").Value, 1, 1))
    For j = 2 To Len(.Cells(i, "C").Value)

    If NumberFlag <> IsNumeric(Mid(.Cells(i, "C").Value, j, 1)) Then

    tmp = tmp & "/"
    NumberFlag = Not NumberFlag
    End If

    tmp = tmp & Mid(.Cells(i, "C").Value, j, 1)
    Next j
    End If

    .Cells(i, "C").Value = tmp
    Next i
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    thanks bob!

Posting Permissions

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