Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel Data Cleaning

Posted on 2015-01-06
7
Medium Priority
?
130 Views
Last Modified: 2015-01-06
I am having problems with cleaning my data.  Currently I am importing data into excel and run a macro that resizes columns, deletes other columns I don't need, and arranges the data in the format I need.  I then copy the results and dump it into another spreadsheet that I then used to perform various calculations.  However, recent I have noticed that several of my formulas aren't calculating.  After some review I noticed that there are extra spaces in the data, so for example I will have IN123456789__, where the under scores are actually spaces.  I want to remove all leading and trailing spaces or hidden characters from this data as it causes problems with my formulas.

I have tired the trim formula, which works until I delete the original data column, I can leave the column and then rewrite the macro to only copy the new trimmed data columns, but that seems like wasted effort.  Is there another way to accomplish this automatically via VB?  

I have attached a copy of the source data so you can see the extra spaces.
waslog-MI-Report.xls
0
Comment
Question by:Rrave26
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40533423
1. Do the trim formula.
2. Select the trimmed formula.
3. Copy
4. Paste - Values Only.
5. You can now delete the original data column.
0
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 40533426
Hi,

you could try

Sub Macro1()
'
' Macro1 Macro
'
For Each c In ActiveSheet.UsedRange
    If Not c.Value = "" And c.HasFormula = False Then
        With c
            .Value = Replace(.Value, Chr(160), "")
            .Value = Application.WorksheetFunction.Clean(.Value)
            .Value = Trim(.Value)
        End With
    End If
Next c

End Sub

Open in new window

Regards
0
 

Author Comment

by:Rrave26
ID: 40533463
Phil, thanks for the response, and your solution will work however I would have to do that almost 20 times.  I was trying to do this all at one time so I could just copy and paste all 20 columns of data at one time.  Unless I have missed something here.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40533467
Then it sounds like you need a VBA solution, and Rgonzo1971 has provided one.
0
 

Author Comment

by:Rrave26
ID: 40533471
Rgonzo,  Thanks for the answer, just to be sure I understand the code, VB newb here, Basically yu are looking in each cell, c, in the active sheet and the cells that have data in it.  Then you are looking at all of the cell that are null and don't have formulas.  This is where I get a bit confused  Not sure what .Value = Replace(.Value, Chr(160), "") does.  And why do the clean step if you have the trim function as well?  

Sorry to be a pain, but just trying to understand so I can support this moving forward.
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 40533497
Char 160 is the non-breaking space which is not handled with trim and is replace with a null-length string (replaced with nothing)

clean removes all non-printable characters
0
 

Author Closing Comment

by:Rrave26
ID: 40533991
The solution works perfectly.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

688 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