Increase decimal macro

R

R Avery

I have the following problem:
I often want to change the position of the decimal place in a cel (i.e.,
change its NumberFormat). However, i am too lazy to use the toolbar button.
Instead, I need something i can bind to a shortcutkey. Unfortunately,
recording the macro yields no interesting results.

Is there a simple, general way to do what I am thinking of, or must the code
for such a macro be necessarily long?

Any help would be appreciated! Thanks.
 
R

R Avery

No, what I am looking for is a lot more general.

I want to have a macro called "IncrementDecimal", or something like that, so
that when i press the shortcutkey it is bound to, it will increase the
decimal of all cells in the selection by 1, just like the button on the
toolbar.

Similarly, I would want a "DecrementDecimal" macro that would do the
reverse.

For example, if i had cells A1:A3 like this
$1,030.45
45.813%
1.1

Then the "DecrementDecimal" macro would, if A1:A3 is selected, change it to
the following:
$1,030.5
45.81%
1
 
D

Dave Peterson

You could write a routine that would parse the .numberformat of each cell in the
selection, but man, there's lots of .numberformats that those buttons respect!

Maybe just running the buttons:

Option Explicit
Sub increaseDecimal()
Application.CommandBars("formatting").FindControl(ID:=398).Execute
End Sub
Sub decreasedecimal()
Application.CommandBars("formatting").FindControl(ID:=399).Execute
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top