Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Format Decimals and Whole Numbers

Is it anyway to setup a cell (Format/Cells/Number/Custom) so when the
number is a whole number, it shows as a whole number and when a number
has a decimal, it shows as a decimal? For example our system has an
eight digit number as the following:

12311001
12412002

They show as:

123-11-001
124-12-002

When we add a mod 1, 2 etc. to the existing number we want it to show
the following:

123-11-001
123-11-001.01
123-11-001.02
124-12-002
124-12-002.01

I'm trying to keep it from adding the 2 zeros to the end of the
original number like the following:

123-11-001.00

Any help would be greatly appreciated.
Darrell

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Format Decimals and Whole Numbers

Darrell,

Copy the code below, right click on the sheet tab, select "View Code" and paste the code into the
window that appears.

Change the B:B to be the column (or columns) where you want to enter the 8 digit numbers.

HTH,
Bernie
MS Excel MVP

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
If Target.Value < Int(Target.Value) Then
Target.NumberFormat = "000-00-000.00"
Else
Target.NumberFormat = "000-00-000"
End If
End Sub



"Lankchevy" wrote in message
oups.com...
Is it anyway to setup a cell (Format/Cells/Number/Custom) so when the
number is a whole number, it shows as a whole number and when a number
has a decimal, it shows as a decimal? For example our system has an
eight digit number as the following:

12311001
12412002

They show as:

123-11-001
124-12-002

When we add a mod 1, 2 etc. to the existing number we want it to show
the following:

123-11-001
123-11-001.01
123-11-001.02
124-12-002
124-12-002.01

I'm trying to keep it from adding the 2 zeros to the end of the
original number like the following:

123-11-001.00

Any help would be greatly appreciated.
Darrell



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Format Decimals and Whole Numbers

Bernie,
It works great.
Thanks for assistance,
Darrell

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Format Decimals and Whole Numbers

Darrell,

Glad to be of help, and thanks for letting me know that you got it to work.

Bernie
MS Excel MVP


"Darrell Lankford" wrote in message
oups.com...
Bernie,
It works great.
Thanks for assistance,
Darrell



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
numbers & decimals chas. New Users to Excel 1 October 15th 07 05:36 AM
Sorting numbers with two decimals Leslie W. Excel Worksheet Functions 4 June 1st 07 08:54 PM
Changing whole numbers into decimals Dos_III Excel Worksheet Functions 3 January 24th 07 03:58 AM
Sorting Decimals as Numbers NathanP1 Excel Discussion (Misc queries) 1 December 13th 06 06:05 PM
sort "numbers" with decimals Melissa Excel Discussion (Misc queries) 4 September 2nd 05 02:28 PM


All times are GMT +1. The time now is 04:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"