Formatting

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

Hi -

Is it possible to add a macro to a toggle button to change the
formatting of a group of cells? Currently, depending on whether the
toggle button is clicked, the cell will show a dollar value or a
percentage and I want the formatting to change from Accounting to
Percentage to reflect the data.

Example -
- When the button is not clicked, the value of cell A1 is 100 and
should be formatted $100.

- When the button is clicked, the value of cell A1 is .30 and should
be formatted 30%.

Any help would be greatly appreciated. Thanks.

Stephen
 
Stephen,

You refer to a group of cells and then to "the cell" so I'm unclear, but
this might help.

Assign this macro to a button from the forms toolbar, and it will toggle
selected cells back and forth. If the cells in the selection start out with
different values it will set them all the same on the first toggle. The
selected cells don't have to be contiguous:

Sub test()

With Selection
If .Cells(1).Value = 100 Then
.Value = 0.3
.NumberFormat = "0%"
Else
.Value = 100
.NumberFormat = "_($* #,##0_);_($* (#,##0);_($* ""-""_);_(@_)"
End If
End With

End Sub

hth,

Doug
 
Back
Top