PC Review


Reply
Thread Tools Rate Thread

How to check the decimal number of each cells vaue in the column

 
 
tlee
Guest
Posts: n/a
 
      26th May 2009
Hi all,

As refer to my pervious post, I would like to use Macro VBA to check the
last digit (1 to 9) of the
cell value automatically?

My code as below: (may be it is complicated coding)

For Each Col In Range("A2:A9999")

If Col.Value <> "" Then
If Col.Value > 10 And Col.Value <= 9999 Then
Ans = Col.Value Mod 10
If Ans <> 0 Then
Col.Value = Col.Value * 10
Else
Col.Value = Col.Value
End If
End If
End If

Next Col

e.g.
Cell A1 = 21, 22 ........, 29 then it will be multiply by 10
Cell A2 = 201, 202, ........., 209 then it will be multiply by 10


However, how can I check with the data which is decimal number too, such
that 3.9 , 33.9 ......................... convert to 390,
3390...............................?

Thanks
tlee

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      26th May 2009
right(COL.VALUE,1) = "9"

OR
VAL(right(COL.VALUE,1)) = 9

Right returns a string so you either have to compare to a string or convert
the string to a number.


"tlee" wrote:

> Hi all,
>
> As refer to my pervious post, I would like to use Macro VBA to check the
> last digit (1 to 9) of the
> cell value automatically?
>
> My code as below: (may be it is complicated coding)
>
> For Each Col In Range("A2:A9999")
>
> If Col.Value <> "" Then
> If Col.Value > 10 And Col.Value <= 9999 Then
> Ans = Col.Value Mod 10
> If Ans <> 0 Then
> Col.Value = Col.Value * 10
> Else
> Col.Value = Col.Value
> End If
> End If
> End If
>
> Next Col
>
> e.g.
> Cell A1 = 21, 22 ........, 29 then it will be multiply by 10
> Cell A2 = 201, 202, ........., 209 then it will be multiply by 10
>
>
> However, how can I check with the data which is decimal number too, such
> that 3.9 , 33.9 ......................... convert to 390,
> 3390...............................?
>
> Thanks
> tlee
>
>

 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      31st May 2009
Hi Joel,

Thanks for your message.
If I want to check the digit which is 2 decimal point such that

X.X1
X.X2
....
....
....
X.X8
X.X9

Have any more smart way to implement?

Thanks
tlee


> right(COL.VALUE,1) = "9"
>
> OR
> VAL(right(COL.VALUE,1)) = 9
>
> Right returns a string so you either have to compare to a string or
> convert
> the string to a number.
>
>
> "tlee" wrote:
>
>> Hi all,
>>
>> As refer to my pervious post, I would like to use Macro VBA to check the
>> last digit (1 to 9) of the
>> cell value automatically?
>>
>> My code as below: (may be it is complicated coding)
>>
>> For Each Col In Range("A2:A9999")
>>
>> If Col.Value <> "" Then
>> If Col.Value > 10 And Col.Value <= 9999 Then
>> Ans = Col.Value Mod 10
>> If Ans <> 0 Then
>> Col.Value = Col.Value * 10
>> Else
>> Col.Value = Col.Value
>> End If
>> End If
>> End If
>>
>> Next Col
>>
>> e.g.
>> Cell A1 = 21, 22 ........, 29 then it will be multiply by 10
>> Cell A2 = 201, 202, ........., 209 then it will be multiply by 10
>>
>>
>> However, how can I check with the data which is decimal number too, such
>> that 3.9 , 33.9 ......................... convert to 390,
>> 3390...............................?
>>
>> Thanks
>> tlee
>>
>>



 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      31st May 2009
right with the parameter 1 will always check the right digit of the number.
You will have a problem using this method if you have numbers which are 1 and
2 decimal points like

right(COL.VALUE,1) = "1"

1.1
1.11

The numbers should be
1.10
1.11

Using format will correct for this problem

right(format(COL.VALUE,"0.00"),1) = "1"

the format statement will convert all the numbers to two decimal places
which is the same as changing the format of the cells to numbers with 2
decimal places (worksheet menu format - cells - numbers).


My code will match both number in the first example and only 1.11 in the 2nd
example.

"tlee" wrote:

> Hi Joel,
>
> Thanks for your message.
> If I want to check the digit which is 2 decimal point such that
>
> X.X1
> X.X2
> ....
> ....
> ....
> X.X8
> X.X9
>
> Have any more smart way to implement?
>
> Thanks
> tlee
>
>
> > right(COL.VALUE,1) = "9"
> >
> > OR
> > VAL(right(COL.VALUE,1)) = 9
> >
> > Right returns a string so you either have to compare to a string or
> > convert
> > the string to a number.
> >
> >
> > "tlee" wrote:
> >
> >> Hi all,
> >>
> >> As refer to my pervious post, I would like to use Macro VBA to check the
> >> last digit (1 to 9) of the
> >> cell value automatically?
> >>
> >> My code as below: (may be it is complicated coding)
> >>
> >> For Each Col In Range("A2:A9999")
> >>
> >> If Col.Value <> "" Then
> >> If Col.Value > 10 And Col.Value <= 9999 Then
> >> Ans = Col.Value Mod 10
> >> If Ans <> 0 Then
> >> Col.Value = Col.Value * 10
> >> Else
> >> Col.Value = Col.Value
> >> End If
> >> End If
> >> End If
> >>
> >> Next Col
> >>
> >> e.g.
> >> Cell A1 = 21, 22 ........, 29 then it will be multiply by 10
> >> Cell A2 = 201, 202, ........., 209 then it will be multiply by 10
> >>
> >>
> >> However, how can I check with the data which is decimal number too, such
> >> that 3.9 , 33.9 ......................... convert to 390,
> >> 3390...............................?
> >>
> >> Thanks
> >> tlee
> >>
> >>

>
>
>

 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      5th Jun 2009
Hi Joel,

Thanks for your help!

Tlee


> right with the parameter 1 will always check the right digit of the
> number.
> You will have a problem using this method if you have numbers which are 1
> and
> 2 decimal points like
>
> right(COL.VALUE,1) = "1"
>
> 1.1
> 1.11
>
> The numbers should be
> 1.10
> 1.11
>
> Using format will correct for this problem
>
> right(format(COL.VALUE,"0.00"),1) = "1"
>
> the format statement will convert all the numbers to two decimal places
> which is the same as changing the format of the cells to numbers with 2
> decimal places (worksheet menu format - cells - numbers).
>
>
> My code will match both number in the first example and only 1.11 in the
> 2nd
> example.
>
> "tlee" wrote:
>
>> Hi Joel,
>>
>> Thanks for your message.
>> If I want to check the digit which is 2 decimal point such that
>>
>> X.X1
>> X.X2
>> ....
>> ....
>> ....
>> X.X8
>> X.X9
>>
>> Have any more smart way to implement?
>>
>> Thanks
>> tlee
>>
>>
>> > right(COL.VALUE,1) = "9"
>> >
>> > OR
>> > VAL(right(COL.VALUE,1)) = 9
>> >
>> > Right returns a string so you either have to compare to a string or
>> > convert
>> > the string to a number.
>> >
>> >
>> > "tlee" wrote:
>> >
>> >> Hi all,
>> >>
>> >> As refer to my pervious post, I would like to use Macro VBA to check
>> >> the
>> >> last digit (1 to 9) of the
>> >> cell value automatically?
>> >>
>> >> My code as below: (may be it is complicated coding)
>> >>
>> >> For Each Col In Range("A2:A9999")
>> >>
>> >> If Col.Value <> "" Then
>> >> If Col.Value > 10 And Col.Value <= 9999 Then
>> >> Ans = Col.Value Mod 10
>> >> If Ans <> 0 Then
>> >> Col.Value = Col.Value * 10
>> >> Else
>> >> Col.Value = Col.Value
>> >> End If
>> >> End If
>> >> End If
>> >>
>> >> Next Col
>> >>
>> >> e.g.
>> >> Cell A1 = 21, 22 ........, 29 then it will be multiply by 10
>> >> Cell A2 = 201, 202, ........., 209 then it will be multiply by 10
>> >>
>> >>
>> >> However, how can I check with the data which is decimal number too,
>> >> such
>> >> that 3.9 , 33.9 ......................... convert to 390,
>> >> 3390...............................?
>> >>
>> >> Thanks
>> >> tlee
>> >>
>> >>

>>
>>
>>

 
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 if a number has no more than 2 decimal digits zxcv Microsoft Excel Programming 12 25th Mar 2010 02:06 PM
How to check the last digit of each cells vaue in the column tlee Microsoft Excel Programming 7 5th Jun 2009 02:18 AM
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
Add Decimal to Cells 2 places to left of number. dlkingace Microsoft Excel Misc 3 15th Nov 2004 07:06 PM
Changing a column's number of decimal places Shaun Allan Microsoft Excel Programming 2 24th Jul 2004 03:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:49 PM.