PC Review


Reply
Thread Tools Rate Thread

Check if there is a decimal point

 
 
=?Utf-8?B?SmFub3M=?=
Guest
Posts: n/a
 
      5th Apr 2007
Hello,

Within a for loop i need to check if and where a value has a decimal point,
and then amend/add a decimal point. Ie:
100.11 -> 100.11
100.1 -> 10.01
100 -> 1.00

I have tried convoluted ways o check such as Right(Left(c.value,3),1)="."
but it doesn't ever want to...

Any ideas, suggestions?

Much Appreciated,

Janos
 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      5th Apr 2007
Try c.Text instead of c.Value, and use InStr(c.Text, ".")>0 as an initial
screen for the point. To see if a six-character string has a decimal point
in its 4th position: Mid$(c.Text, Len(c.Text)-2, 1)="."

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Janos" <(E-Mail Removed)> wrote in message
news:01AEDA55-35B0-4CFE-9C2E-(E-Mail Removed)...
> Hello,
>
> Within a for loop i need to check if and where a value has a decimal
> point,
> and then amend/add a decimal point. Ie:
> 100.11 -> 100.11
> 100.1 -> 10.01
> 100 -> 1.00
>
> I have tried convoluted ways o check such as Right(Left(c.value,3),1)="."
> but it doesn't ever want to...
>
> Any ideas, suggestions?
>
> Much Appreciated,
>
> Janos



 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      5th Apr 2007
Hi Janos,

Your rules for the movement of the decimal point
are not clear to me, but try something like:

'=============>>
Public Sub TesterB002()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim rCell As Range
Dim sStr As String
Dim iLastRow As Long
Dim iPos As Long

Set WB = Workbooks("MyBook.xls") '<<=== CHANGE
Set SH = WB.Sheets("Sheet1") '<<=== CHANGE
Set Rng = SH.Range("A2:A100") '<<=== CHANGE

For Each rCell In Rng.Cells
With rCell
If IsNumeric(.Value) _
And Not IsEmpty(.Value) Then

sStr = Replace(.Value, ".", vbNullString, 1)
iPos = InStr(1, .Value, ".")
Select Case iPos
Case 0: .Value = Left(sStr, 1) _
& "." & Mid(sStr, 2)
Case 3: .Value = .Value = Left(sStr, 2) _
& "." & Mid(sStr, 3)
End Select
.Value = CDbl(.Value)
End If
End With
Next rCell
Rng.NumberFormat = "0.00"
End Sub
'<<=============


---
Regards,
Norman


"Janos" <(E-Mail Removed)> wrote in message
news:01AEDA55-35B0-4CFE-9C2E-(E-Mail Removed)...
> Hello,
>
> Within a for loop i need to check if and where a value has a decimal
> point,
> and then amend/add a decimal point. Ie:
> 100.11 -> 100.11
> 100.1 -> 10.01
> 100 -> 1.00
>
> I have tried convoluted ways o check such as Right(Left(c.value,3),1)="."
> but it doesn't ever want to...
>
> Any ideas, suggestions?
>
> Much Appreciated,
>
> Janos



 
Reply With Quote
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      5th Apr 2007

Your examples are not very clear, but based on what you have provided, I
think this will work:

Sub test()
Dim strText As String
strText = "1234"

strText = Replace(strText, ".", "")
strText = Left(strText, Len(strText) - 2) & "." & Right(strText, 2)

End Sub



--
Hope that helps.

Vergel Adriano


"Janos" wrote:

> Hello,
>
> Within a for loop i need to check if and where a value has a decimal point,
> and then amend/add a decimal point. Ie:
> 100.11 -> 100.11
> 100.1 -> 10.01
> 100 -> 1.00
>
> I have tried convoluted ways o check such as Right(Left(c.value,3),1)="."
> but it doesn't ever want to...
>
> Any ideas, suggestions?
>
> Much Appreciated,
>
> Janos

 
Reply With Quote
 
=?Utf-8?B?SmFub3M=?=
Guest
Posts: n/a
 
      11th Apr 2007
Thank you all for your help, I solved it by treating it like a string.

Janos

"Janos" wrote:

> Hello,
>
> Within a for loop i need to check if and where a value has a decimal point,
> and then amend/add a decimal point. Ie:
> 100.11 -> 100.11
> 100.1 -> 10.01
> 100 -> 1.00
>
> I have tried convoluted ways o check such as Right(Left(c.value,3),1)="."
> but it doesn't ever want to...
>
> Any ideas, suggestions?
>
> Much Appreciated,
>
> Janos

 
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
How to check the decimal point of floating number using macro??? =?Utf-8?B?SmFj?= Microsoft Excel Programming 4 16th May 2007 06:36 PM
Converting 2-place decimal value to floating point decimal number with leading zero Kermit Piper Microsoft Excel Misc 3 18th Mar 2006 06:20 PM
FIXED 2 DECIMAL PLACES, MUST ENTER ALL ZEROES AFTER DECIMAL POINT. =?Utf-8?B?U1VLWUtJVFRZ?= Microsoft Excel Misc 3 6th Jul 2005 01:50 PM
setting the decimal variable to include 2 numbers after decimal point? Scott Microsoft VB .NET 1 3rd Mar 2005 10:05 PM
Decimal class now preserves trailing zeroes after the decimal point Uncle Goh Microsoft Dot NET Framework 0 11th Sep 2003 09:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:32 AM.