PC Review


Reply
Thread Tools Rate Thread

Coverting strings to numbers and trimming trailing zeros

 
 
S Himmelrich
Guest
Posts: n/a
 
      1st Feb 2008
Basically, I've tried to format the cell in a macro and as it's a
string it's not reformatting so this is the case I'm trying to
resolve . . .

My original data looks like this:

151.00
1.00
2.25
16.00
16.20

I'm looking for a result like this""
151
1
2.25
16
16.2

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      1st Feb 2008
Try formatting the range as General
Then edit|replace
what: . (decimal point)
with: .
replace all

Record a macro when you do it in code and you should be ok.

S Himmelrich wrote:
>
> Basically, I've tried to format the cell in a macro and as it's a
> string it's not reformatting so this is the case I'm trying to
> resolve . . .
>
> My original data looks like this:
>
> 151.00
> 1.00
> 2.25
> 16.00
> 16.20
>
> I'm looking for a result like this""
> 151
> 1
> 2.25
> 16
> 16.2


--

Dave Peterson
 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      1st Feb 2008
Take the Value for each

=Value(A1) on the worksheet

or

Val(myValue) in code

Then format as a numeric.

--

Regards,
Nigel
(E-Mail Removed)



"S Himmelrich" <(E-Mail Removed)> wrote in message
news:b7fe9c16-490d-400f-8465-(E-Mail Removed)...
> Basically, I've tried to format the cell in a macro and as it's a
> string it's not reformatting so this is the case I'm trying to
> resolve . . .
>
> My original data looks like this:
>
> 151.00
> 1.00
> 2.25
> 16.00
> 16.20
>
> I'm looking for a result like this""
> 151
> 1
> 2.25
> 16
> 16.2
>


 
Reply With Quote
 
S Himmelrich
Guest
Posts: n/a
 
      1st Feb 2008
I'm reading your comment as replacing a "." with a ".", hence I don't
understand how that helps...I've done what you have mentioned, but I
have the original results.

On Feb 1, 11:27*am, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> Try formatting the range as General
> Then edit|replace
> what: *. *(decimal point)
> with: *.
> replace all
>
> Record a macro when you do it in code and you should be ok.
>
>
>
>
>
> S Himmelrich wrote:
>
> > Basically, I've tried to format the cell in a macro and as it's a
> > string it's not reformatting so this is the case I'm trying to
> > resolve . . .

>
> > My original data looks like this:

>
> > 151.00
> > 1.00
> > 2.25
> > 16.00
> > 16.20

>
> > I'm looking for a result like this""
> > 151
> > 1
> > 2.25
> > 16
> > 16.2

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


 
Reply With Quote
 
S Himmelrich
Guest
Posts: n/a
 
      1st Feb 2008
tried with and without code and this doesn't work...

On Feb 1, 11:30*am, "Nigel" <nigel-...@nosupanetspam.com> wrote:
> Take the Value for each
>
> =Value(A1) * * on the worksheet
>
> or
>
> Val(myValue) in code
>
> Then format as a numeric.
>
> --
>
> Regards,
> Nigel
> nigelnos...@9sw.co.uk
>
> "S Himmelrich" <himmelr...@gmail.com> wrote in message
>
> news:b7fe9c16-490d-400f-8465-(E-Mail Removed)...
>
>
>
> > Basically, I've tried to format the cell in a macro and as it's a
> > string it's not reformatting so this is the case I'm trying to
> > resolve . . .

>
> > My original data looks like this:

>
> > 151.00
> > 1.00
> > 2.25
> > 16.00
> > 16.20

>
> > I'm looking for a result like this""
> > 151
> > 1
> > 2.25
> > 16
> > 16.2- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      1st Feb 2008
On Fri, 1 Feb 2008 08:14:42 -0800 (PST), S Himmelrich <(E-Mail Removed)>
wrote:

>Basically, I've tried to format the cell in a macro and as it's a
>string it's not reformatting so this is the case I'm trying to
>resolve . . .
>
>My original data looks like this:
>
>151.00
>1.00
>2.25
>16.00
>16.20
>
>I'm looking for a result like this""
>151
>1
>2.25
>16
>16.2


Although you did not mention it, I assume you want your values to be numbers
and right justified.

With your numbers starting in A1, something like this might work:

======================
Option Explicit
Sub cellformat()
Dim c As Range
Set c = Range("a1").CurrentRegion
c.NumberFormat = "General"
c.Value = c.Value
End Sub
=======================


--ron
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      1st Feb 2008
And you did change the numberformat to General first, right?

If yes, then changing the dot to dot will make excel reevalate the stuff in each
cell. If they're really numbers, then excel will see them as numbers. And with
a general format, the trailing .00 won't show.

But it sounds like your values aren't really digits (and dots).

If you got the data from a web page, then you may have HTML non-breaking spaces
in your data.

David McRitchie has a macro that can help clean this:
http://www.mvps.org/dmcritchie/excel/join.htm#trimall
(look for "Sub Trimall()")

And if you're new to macros, you may want to read David's intro:
http://www.mvps.org/dmcritchie/excel/getstarted.htm


S Himmelrich wrote:
>
> I'm reading your comment as replacing a "." with a ".", hence I don't
> understand how that helps...I've done what you have mentioned, but I
> have the original results.
>
> On Feb 1, 11:27 am, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> > Try formatting the range as General
> > Then edit|replace
> > what: . (decimal point)
> > with: .
> > replace all
> >
> > Record a macro when you do it in code and you should be ok.
> >
> >
> >
> >
> >
> > S Himmelrich wrote:
> >
> > > Basically, I've tried to format the cell in a macro and as it's a
> > > string it's not reformatting so this is the case I'm trying to
> > > resolve . . .

> >
> > > My original data looks like this:

> >
> > > 151.00
> > > 1.00
> > > 2.25
> > > 16.00
> > > 16.20

> >
> > > I'm looking for a result like this""
> > > 151
> > > 1
> > > 2.25
> > > 16
> > > 16.2

> >
> > --
> >
> > Dave Peterson- Hide quoted text -
> >
> > - Show quoted text -


--

Dave Peterson
 
Reply With Quote
 
S Himmelrich
Guest
Posts: n/a
 
      1st Feb 2008
Talk about tricks of the trade...thank you much.

On Feb 1, 12:22*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> And you did change the numberformat to General first, right?
>
> If yes, then changing the dot to dot will make excel reevalate the stuff in each
> cell. *If they're really numbers, then excel will see them as numbers. *And with
> a general format, the trailing .00 won't show.
>
> But it sounds like your values aren't really digits (and dots).
>
> If you got the data from a web page, then you may have HTML non-breaking spaces
> in your data.
>
> David McRitchie has a macro that can help clean this:http://www.mvps.org/dmcritchie/excel/join.htm#trimall
> (look for "Sub Trimall()")
>
> And if you're new to macros, you may want to read David's intro:http://www..mvps.org/dmcritchie/excel/getstarted.htm
>
>
>
>
>
> S Himmelrich wrote:
>
> > I'm reading your comment as replacing a "." with a ".", hence I don't
> > understand how that helps...I've done what you have mentioned, but I
> > have the original results.

>
> > On Feb 1, 11:27 am, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> > > Try formatting the range as General
> > > Then edit|replace
> > > what: *. *(decimal point)
> > > with: *.
> > > replace all

>
> > > Record a macro when you do it in code and you should be ok.

>
> > > S Himmelrich wrote:

>
> > > > Basically, I've tried to format the cell in a macro and as it's a
> > > > string it's not reformatting so this is the case I'm trying to
> > > > resolve . . .

>
> > > > My original data looks like this:

>
> > > > 151.00
> > > > 1.00
> > > > 2.25
> > > > 16.00
> > > > 16.20

>
> > > > I'm looking for a result like this""
> > > > 151
> > > > 1
> > > > 2.25
> > > > 16
> > > > 16.2

>
> > > --

>
> > > Dave Peterson- Hide quoted text -

>
> > > - Show quoted text -

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trailing Zeros aftamath77 Microsoft Excel Misc 3 7th Oct 2008 07:40 PM
trimming strings RobcPettit@yahoo.co.uk Microsoft C# .NET 3 8th Jan 2008 10:48 PM
Import decimal numbers with trailing zeros into Excel =?Utf-8?B?SmFja0NhbGk=?= Microsoft Excel Programming 1 2nd Mar 2007 07:06 PM
Keep numbers as entered with trailing zeros Allie Microsoft Excel Misc 2 3rd Aug 2006 06:39 PM
leading zeros & trailing zeros =?Utf-8?B?Q01jR3Jhbm4=?= Microsoft Access External Data 2 5th May 2006 02:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:46 AM.