Code which I had in another (very similar) Excel project suddenly doesn't work, very simple code. Purpose is to set the min and max value for the X axis of a chart. There is only one chart on the sheet, I tried to loop through all charts in case I had the chart identified incorrectly somehow. the error that I get is 13: type mismatch. For Each cht … is highlighted. I tried it with the for each loop commented out and nothing happens, no errors but no change in the chart either.
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Button4_Click()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Dim cht As Chart[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]For Each cht In ActiveSheet.ChartObjects[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Set cht = ActiveSheet.ChartObjects("Chart 1").Chart[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]'Adjust x-axis Scale
cht.Axes(xlCategory).MinimumScale = 0
cht.Axes(xlCategory).MaximumScale = 90
Next cht[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]End Sub[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub Button4_Click()[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Dim cht As Chart[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]For Each cht In ActiveSheet.ChartObjects[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Set cht = ActiveSheet.ChartObjects("Chart 1").Chart[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]'Adjust x-axis Scale
cht.Axes(xlCategory).MinimumScale = 0
cht.Axes(xlCategory).MaximumScale = 90
Next cht[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]End Sub[/FONT]