Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() ?Replace("32 01 22 88 03", "0", "") Oops! That's going to replac *ALL* zeros; - the task is to replace *LEADING* ZEROS ONLY!! I devised the following solution. Maybe using regular expressions is overkill, but it worked. Here it is: Public Sub MyReplace() ' Include"Microsoft VBScript Regular Expressions 5.5" in Tools-References Dim regEx As New VBScript_RegExp_55.RegExp Dim s1 As String Dim sFinal As String Dim sExample As String sExample = "01 07 08 22 88 06 04" ' Replace leading zeros (in middle of line) regEx.Pattern = " 0" regEx.Global = True regEx.IgnoreCase = False s1 = regEx.Replace(sExample, " ") ' Remove leading zeros (at beginning of line) regEx.Pattern = "^0" regEx.Global = True regEx.IgnoreCase = False sFinal = regEx.Replace(s1, "") MsgBox sFinal End Sub - Robert Crandall |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Remove leading zeros | Excel Discussion (Misc queries) | |||
How can I remove leading zeros? | Excel Programming | |||
How can I remove leading zeros? | Excel Programming | |||
REMOVE LEADING ZEROS | Excel Worksheet Functions | |||
Using VBA to remove leading zeros | Excel Programming |