Solved

Excel Data Cleaning

Posted on 2015-01-06
7
117 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
  • 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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 48

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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 learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

22 Experts available now in Live!

Get 1:1 Help Now