Solved

How can I automate the removal of leading zeros and commas in Excel fields?

Posted on 2014-07-22
3
213 Views
Last Modified: 2014-07-23
In an Excel spreadsheet, using VBA or any other script, I would like to remove leading zeros in field in a specific column, and I would also like to replace commas with nothing.
0
Comment
Question by:100questions
  • 2
3 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40212521
It sound like the column contains numeric data but is formatted as text.  If this is the case I would do the following:

1) Highlight all the data in the column and use the Replace function to replace commas with nothing.
remove commas2) Highlight all the data, click on the alert icon, and then select "Convert to Number"
convert to number
Regards,
-Glenn
0
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40212569
To automate the above steps in VBA (this example applies to column A):
Sub Convert_To_Numbers()
    Dim rng As Range
    Dim cl As Object
    Columns("A:A").Select
    Selection.Replace What:=",", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows
    Set rng = Range("A1:A" & Cells.SpecialCells(xlLastCell).Row)
    rng.NumberFormat = "General"
    For Each cl In rng
        cl.Formula = Trim(cl.Formula)
    Next cl
End Sub

Open in new window


-Glenn
0
 

Author Comment

by:100questions
ID: 40214132
Thanks Glenn.  Seems to work after I enter the correct columns and fix the range to what I need.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Troubleshooting a Worksheet Graphic 8 25
Formula 6 45
Excel copy picture into Outlook email 7 41
Access Excel export not behaving 2 24
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now