Solved

How do I clean the data in a cell or special characters, spaces, and carriage returns?

Posted on 2015-01-31
2
83 Views
Last Modified: 2016-02-10
I am trying to clean and normalize data. Cells have carriage returns in them (Alt+Enter), special characters (%^*)/!~), and blank non printing characters. I have come across a few different methods, but each is a separate operation.

Is there a way to select the cells in question, and have a macro perform it all?

The attached file has the three different processes that I have found so far. Two are subs and one is a function. I am hoping to combine them so that one macro can do all three exercises at once.

Thanks for having a look....
Remove-Returns-And-Special-Characters.xl
0
Comment
Question by:DougDodge
2 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40582390
Hi,

pls try

Sub RemoveAll()
Dim cel
Dim strTmp, strSpecialChars
Dim i

For Each cel In ActiveSheet.UsedRange
    strTmp = Trim(Application.Clean(Replace(cel, Chr(10), " ")))
    strSpecialChars = "\/:*?™""®<>|.&@#(_+`©~);-+=^$!,'" 'This is your list of characters to be removed
    
    For i = 1 To Len(strSpecialChars)
        strTmp = Replace$(strTmp, Mid$(strSpecialChars, i, 1), "") 'this will remove spaces
    Next
    strTmp = Replace$(strTmp, "  ", " ")
    cel.Value = strTmp
Next
    
End Sub

Open in new window

Regards
0
 

Author Comment

by:DougDodge
ID: 40583208
It worked, just the way I had hoped.....

Thanks....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lately there has been a variety of news related to U.S. employment.  Stories about worker productivity, automobile and airline unions, low employment and foreign laborers have frequented the news.  Each story has good and bad attributes we might arg…
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now