Solved

Trim cells in excel

Posted on 2016-07-21
10
58 Views
Last Modified: 2016-07-21
I have a column of cells that has in Column F. They look like a dollar value ie: $4,124.15 but they are not acting like one. They were copied and pasted into the sheet from the internet. I believe every one of them has two spaces after the value (obviously invisible).

What is the easiest way to get them to act like numbers? I believe the two spaces after it is what is making it act weird. I tried Trim(F1) and it doesn't help. Any other options?

Thanks!

Chris
0
Comment
Question by:cansevin
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 41723146
Hi,

Could you send a dummy example?

Regards
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 41723165
Format the col as currency ?

Copy the col out to another sheet first.
0
 

Author Comment

by:cansevin
ID: 41723191
Yes. See attached. Thanks for the help!
0
 

Author Comment

by:cansevin
ID: 41723192
Here it is
Bad-Numbers.xlsx
0
 
LVL 7

Expert Comment

by:tomfarrar
ID: 41723197
Are the numbers showing up on the left side of the cell?  Probably considered text.  The data may need to be trimmed (get rid of excess spaces) using the =trim() function, then converted to a number using (I think) the =value() function.  An example would be helpful as suggested earlier.
0
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.

 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 41723203
Public Sub loopy()
Dim i As Long
Dim wS As Worksheet

Set wSheet = ActiveWorkbook.Worksheets("sheet1")


For i = 1 To Rows.Count
    If InStr(1, wSheet.Cells(i, 3).Value, Chr(32)) Then
        wSheet.Cells(i, 3).Value = Replace(wSheet.Cells(i, 3).Value, Chr(32), "")
    End If
Next i
End Sub
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41723211
Please try this...

Sub FixAllNumbers()
ActiveSheet.UsedRange.Replace Chr(160), ""
End Sub

Open in new window

0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41723215
HI,

to change the values in number to be formatted afterwards then try
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,CHAR(160),""),",",""),"$","")

Open in new window

Regards
Bad-NumbersV1.xlsx
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 41723223
Public Sub loopy()
Dim i As Long
Dim wS As Worksheet

Set wSheet = ActiveWorkbook.Worksheets("sheet1")


For i = 1 To Rows.Count
    If InStr(1, wSheet.Cells(i, 3).Value, Chr(160)) Then
        wSheet.Cells(i, 3).Value = Replace(wSheet.Cells(i, 3).Value, Chr(160), "")
        Debug.Print wSheet.Cells(i, 3).Value
    End If
Next i
End Sub
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 41723380
The accepted solution still leaves the values as text. If using directly in an onward calculation that won't matter.

When re-calculating a reference to a single cell Excel will re-evaluate the contents of the cell and will recognise it as a number and deal with it.

However, summing a range of cells that look like numbers but are still text won't work.  

To amend the accepted formula just add *1 on the end ie:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,CHAR(160),""),",",""),"$","")*1

Thanks
Rob H
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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

895 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

14 Experts available now in Live!

Get 1:1 Help Now