Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Increasing and decreasing numbers by 5% ....also showing a loss | Excel Discussion (Misc queries) | |||
increasing or decreasing a cell | Excel Worksheet Functions | |||
increasing height of cells without decreasing size of data | New Users to Excel | |||
shortcut for increasing or decreasing the number of decimals | Excel Worksheet Functions | |||
increasing and decreasing a value in a cell | Excel Worksheet Functions |