Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Decreasing/Increasing decimal places

One of my colleagues has asked for a macro that will
increase or decrease the number of decimal places of a
number. I know the toolbar button does this very nicely,
but he wants a short-cut key.

So if the number is 54.37, he wants code (executed by
shortcut keys) that will decrease/increase the decimal
places by one each time he runs it.

Thanks in advance for any help.

regards
Daniel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Decreasing/Increasing decimal places

How would the macro know whether he wants to increase or decrease the number
of decimal places.

Basically you would need to detect the number of zeros on the right of the
decimal point for the numberformat

Sub testDecimal_Add()
If Not IsNumeric(ActiveCell) Then Exit Sub
sStr = ActiveCell.NumberFormat
If InStr(sStr, ".") Then
iloc = InStr(sStr, ".")
numDecimal = Len(sStr) - iloc
ActiveCell.NumberFormat = Left(sStr, iloc) & String(numDecimal + 1, "0")
Else
ActiveCell.NumberFormat = "#.0"
End If


Sub testDecimal_Subtract()
If Not IsNumeric(ActiveCell) Then Exit Sub
sStr = ActiveCell.NumberFormat
If InStr(sStr, ".") Then
iloc = InStr(sStr, ".")
numDecimal = Len(sStr) - iloc
If numDecimal 0 Then
ActiveCell.NumberFormat = Left(sStr, iloc) & String(numDecimal - 1, "0")
End If
Else
ActiveCell.NumberFormat = "#.0"
End If
End Sub

Might be a start.

Regards,
Tom Ogilvy




"Daniel Bonallack" wrote in message
...
One of my colleagues has asked for a macro that will
increase or decrease the number of decimal places of a
number. I know the toolbar button does this very nicely,
but he wants a short-cut key.

So if the number is 54.37, he wants code (executed by
shortcut keys) that will decrease/increase the decimal
places by one each time he runs it.

Thanks in advance for any help.

regards
Daniel



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
Increasing and decreasing numbers by 5% ....also showing a loss Karen Excel Discussion (Misc queries) 2 April 12th 09 03:44 AM
increasing or decreasing a cell gma Excel Worksheet Functions 16 March 5th 09 12:48 AM
increasing height of cells without decreasing size of data joaniep New Users to Excel 1 July 19th 08 07:02 PM
shortcut for increasing or decreasing the number of decimals JorisBK Excel Worksheet Functions 1 April 8th 08 03:44 PM
increasing and decreasing a value in a cell cwal Excel Worksheet Functions 6 April 14th 06 06:55 PM


All times are GMT +1. The time now is 08:56 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"