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
Solved

Trim cells in excel

Posted on 2016-07-21
10
66 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 50

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 

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 30

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 50

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

860 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