Dynamic label and axis format in Excel

Mark McInerney

Active Member
Joined
Apr 4, 2012
Messages
266
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a row of data, that is driven by an If then else statement - i.e. if cell a1 = 1 then the output is euro data, or, if cell a2 = 2 then the output is percentage data.

I want to graph the data.

Is there a way to tag the axis and labels to a format depending on the value in cell A1? i.e. A1 = 1 format €, or Cell A1 = 2 format %.

Any help or thoughts...genuinely appreciated.

Best - Mark.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hello,

I have assumed your graph/data is the same, its just the format/labels that you require changing. I have also assumed that you have already created the graph, and that cell A1 is manually entered, but I guess some (or all) of these are in-correct.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
        Select Case Target.Value
            Case 1
                ActiveSheet.ChartObjects("Chart 1").Activate
                ActiveChart.Axes(xlValue).Select
                Selection.TickLabels.NumberFormat = "0.00%"
                ActiveChart.SeriesCollection(1).Select
                ActiveChart.SeriesCollection(1).DataLabels.Select
                Selection.NumberFormat = "0.00%"
            Case 2
                ActiveSheet.ChartObjects("Chart 1").Activate
                ActiveChart.Axes(xlValue).Select
                Selection.TickLabels.NumberFormat = "[$€-2] #,##0.00"
                ActiveChart.ChartArea.Select
                ActiveChart.SeriesCollection(1).DataLabels.Select
                Selection.NumberFormat = "[$€-2] #,##0.00"
        End Select
    End If
    Range("A1").Select
End Sub

This was created from using the macro recorder, so you may need to change references.
 
Upvote 0

Forum statistics

Threads
1,216,190
Messages
6,129,421
Members
449,509
Latest member
ajbooisen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top