Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trim cells in excel

Posted on 2016-07-21
10
Medium Priority
?
80 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
[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
  • +3
10 Comments
 
LVL 53

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
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!

 

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
 
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 33

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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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 33

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

636 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