We help IT Professionals succeed at work.

Excel 2010 - Remove all "0" field prefixes

Murphy1992
Murphy1992 asked
on
45 Views
Last Modified: 2016-03-29
Hi
From a Supplier's site we are able to download our monthly statements in a csv or excel format.  Either works well with the exception that the file applies a varying number of "0" prefixes to the invoice numbers.  

This Supplier's statement is a consolidation of numerous Suppliers invoices for the month - there in lies the problem.  The invoice numbers remain the same as supplied by individual supplier but once consolidated to a single Supplier statement all invoice numbers are padded to a length of 20 characters.  Depending on the individual supplier invoice numbering (can be alpha numeric) will depend on the number of "0" prefixes applied to make it up the single Supplier statement length of 20 characters.

i.e. the number of the "0" prefixes applied to each invoice vary from 1 up to 16.

Any suggestions on how to easily remove these?

We have tried the obvious solutions such as search and replace & length formulas.
Sample-0-Prefix.xlsx
Comment
Watch Question

Kavi PachkawadeSQL Developer
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
you may try use a regular expression to remove the leading zeros, like:

Function trimStart(v)
    Dim regex As Object
    Set regex = CreateObject("VBScript.RegExp")
    
    With regex
      .Pattern = "^0+(?!$)"
      .Global = True
    End With
    
    trimStart = regex.Replace(v, "")
End Function

Open in new window


then apply it like:
=trimStart(E2)

Open in new window

Sample-0-Prefix_b.xlsm
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Wouldn't it work to just format the column as a number or as general?
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.