?
Solved

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

Posted on 2014-07-22
3
Medium Priority
?
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 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