title: Excel VBA code to set x-axis to minimum and maximum value in plotted range
body: <p>I have a VBA code (below) that sets the min and max x-axis values to a specified cell (B4 and B15). However, I have many plots in my workbook, and all need a different min and max x-axis range. I want a VBA code that goes to the plotted x-axis range and then finds the min and max value in that range and sets the axis to those values. How can I alter the code below to do that?</p>
  
  <pre><code>Sub Resize_Fonts()
  Dim Sht As Worksheet
  Dim Cht As ChartObject
  
  For Each Sht In ActiveWorkbook.Sheets
      For Each Cht In Sht.ChartObjects
          Cht.Chart.ChartArea.Font.Size = 9
          Cht.Chart.ChartArea.Font.Name = "Cambria"
          Cht.Chart.ChartArea.Border.LineStyle = xlNone
          Cht.Chart.Axes(xlValue).MinimumScale = 0
          Cht.Chart.Axes(xlCategory).MinimumScale = Range("B4").Value
          Cht.Chart.Axes(xlCategory).MaximumScale = Range("B15").Value
  
  
      Next Cht
  Next Sht
  
  End Sub
  </code></pre>