r/excel•
cnuthead

Edit Horizontal Axis Using VBA

solved

Hello there,

I have an easy one.... I think.

I have a chart that I need to update the horizontal axis of when I add data.

I have created a simple button that will ask for user input to specify the column the data should go to.

VBA is as follows:

Private Sub EditHorizontalAxis_Click()
Dim myValue As Variant
myValue = InputBox("Enter the column your data now goes to", "Edit Horizontal Axis")
Range("A1").Value = myValue

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(1).XValues = _"='2018 Closed Incidents'!$Q$3:$AL$3"
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.FullSeriesCollection(1).XValues = _"='2018 Closed Incidents'!$Q$3:$AL$3"

End Sub

I need to edit the AL in the two charts to the input. not sure how to add the myValue in there?

Thanks!

Posted Sep 7, 2018, 1:31 AM UTC · edited

36
Loading comments…