You are here:

Excel/Macro to Scrub Data

Advertisement


Question
I have a database that was created by scanning a document with OCR software.  Column (D) has $ values, but they formatted very strangely, and randomly, as illustrated below:

$1 .43   BLANK BEFORE DECIMAL
2.41   CORRECT
$6. 77   BLANK AFTER DECIMAL
$1 . 96   BLANK BEFORE AND AFTER DECIMAL
$1 . 05   BLANK BEFORE AND AFTER DECIMAL
$3. 62   BLANK AFTER DECIMAL
60.58   CORRECT
$38. 25   BLANK AFTER DECIMAL
1.43   CORRECT
36.00   CORRECT
27.00   CORRECT
2.16   CORRECT
$1 . 37   BLANK BEFORE AND AFTER DECIMAL
$2. 53   BLANK AFTER DECIMAL

Is it possible to write a macro to evaluate every cell, find and delete the blank characters, and leave the remaining characters as a numeric value?

Answer
Wayne,

I would just select the column (assuming all the data is in a single column) and do Replace,

put in a space in the first textbox and nothing in the second textbox and then choose replace all

Using your data that produced:
$1.43
$2.41
$6.77
$1.96
$1.05
$3.62
$60.58
$38.25
$1.43
$36.00
$27.00
$2.16
$1.37
$2.53


for me.  (I did some formatting after all the spaces were removed).  

So I would try that first.  If that doesn't work, send me the data in a worksheet and I will see if the spaces are actually spaces or some other non-printing character.

twogilvy@msn.com

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.