View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
EricG EricG is offline
external usenet poster
 
Posts: 220
Default Chart Number Decimal Places

I also added a command button which gathers the names of all charts on the
sheet and creates a named range with them. Then I added data validation in
one cell that is based on that list. Finally, I modified the spin button
code to reference whichever chart is selected in the cell with the data
validation. It works pretty well!

One thing I forgot to do - when you select a new chart in the data
validation cell, it should set the current value of the spinbutton to the
decimal format for that chart.


'
' This button routine gathers the names of all chartobjects on a worksheet
' and puts them in a named range list on the sheet, which feeds a data
' validation cell on the sheet.
'
Private Sub CommandButton1_Click()
Dim i As Integer
Dim cO As ChartObject
Dim tStr As String
'
i = 0
For Each cO In ActiveSheet.ChartObjects
i = i + 1
ActiveSheet.Cells(i + 1, 9) = cO.Name
Next
ActiveSheet.Range("I2:I" & i).Select
ActiveWorkbook.Names.Add Name:="MyCharts" & ActiveSheet.Name,
RefersToR1C1:= _
"='" & ActiveSheet.Name & "'!R2C9:R" & i + 1 & "C9"
End Sub

'
' Make sure the SpinButton limits are set
' to reasonable minimum (0) and maximum values!
'
Private Sub SpinButton1_Change()
Dim i As Integer
Dim nDec As Integer
Dim decStr As String
'
nDec = Me.SpinButton1.Value
If (nDec < 0) Then nDec = 0
decStr = "0."
For i = 1 To nDec
decStr = decStr & "0"
Next i
'
' Note the use of the cell with the data validation as a way to select
' which chart to change the decimals on
'
ActiveSheet.ChartObjects(ActiveSheet.Cells(9, 6).Text).Select
ActiveChart.Axes(xlValue).TickLabels.NumberFormat = decStr
End Sub