• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change Chart Axis Number Format based on a cell Value

Dokat

Member
Ss it possible to write a code where number formatting in Chart Axis updates based on another cell value?

For Ex: if D1 equals 1, then chart axis number format is '$0.0,,"
or if D1 value is 2 Axis format changes to 0.0%?
 
Dokat

It does work, as my posts above and the picture below show

upload_2018-2-28_23-19-36.png

This uses a Custom Format of [<=1]0.0%;[>1]$0.00;0

Can you post a sample file, so we can assist you with real data!
 
Do you mean something like this in the sheet's code-module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  With ActiveSheet.ChartObjects("Chart 1").Chart.Axes(xlValue).TickLabels
    Select Case Range("D1").Value
      Case 1
        .NumberFormat = "$0.0,,"
      Case 2
        .NumberFormat = "0.0%"
    End Select
  End With
End Sub
?

Edit post posting: Oh, obviously not.
 
Yes, i modified the code little bit change the reference sheet and cell and getting Compile Error. Thanks

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  With ActiveSheet.ChartObjects("Chart 1").Chart.Axes(xlValue).TickLabels
    Select Case Worksheets.("Source Data")Range("BC1").Value
      Case 1
        .NumberFormat = "$0.0,,"
      Case 2
        .NumberFormat = "0.0%"
    End Select
  End With
End Sub
 
change:
Select Case Worksheets.("Source Data")Range("BC1").Value
to:
Select Case Worksheets("Source Data").Range("BC1").Value
?
 
Back
Top