Solved

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

Posted on 2014-07-22
3
209 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
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…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

706 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

19 Experts available now in Live!

Get 1:1 Help Now