Solved

Excel Data Cleaning

Posted on 2015-01-06
7
127 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 52

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
Industry Leaders: 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 52

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

632 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