Solved

Trim cells in excel

Posted on 2016-07-21
10
49 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 48

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 48

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 31

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

705 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

18 Experts available now in Live!

Get 1:1 Help Now