简体   繁体   中英

How to add a comma before first number in a string using Excel VBA

I need to insert a comma before the first number in a string in an Excel macro so I can split a zip code that is included with a city in an address (there is no space between the city and zip to use). How would I do this?

would a function do? Zip lenght differs, so.

What about this?

    Function kommainstring(s As String)
      Dim i As Byte
      For i = 1 To Len(s)
        If IsNumeric(Mid(s, i, 1)) Then Exit For
      Next i
      kommainstring = Left(s, Len(s) - (Len(s) - i + 1)) & "," & Right(s, (Len(s) - i + 1))
    End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM