title: Excel VBA Set Chartsheet Axis to Logarithmic
body: <h2>Problem</h2>
  <p>I am trying to programmatically fill chartsheets with data on both linear and logarithmic scales.  For some reason, the Axis.ScaleType property is erroring out.</p>
  <h2>Attempted Fixes</h2>
  <p>I have tried forcing the charttype to xyScatter.  The enums <code>xlLinear = xlScaleLinear</code> and <code>xlLogarithmic = xlScaleLogarithmic</code>.  Placement of the <code>Axis.ScaleType = xlScaleLogarithmic</code> has an effect, but fails when <code>SeriesCollection.Count = 0</code>.</p>
  <p>Any suggestions?  A bit of googling shows that this is a relatively common problem.</p>
  <pre><code>Option Explicit
  Private Type xySeries
      Name As String
      X As Range
      Y As Range
      Markers As XlMarkerStyle
      Axis As XlAxisGroup
      Color As XlColorIndex
      Weight As Single
  End Type
  
  Private Type xyAxis
      NumberFormat As String
      ScaleType As XlScaleType
      Minimum As Double
      Maximum As Double
  End Type
  
  'Pass this function the chartsheet name, and and array of data for the series of custom xySeries type
  Private Sub ChartData(sCSName As String, asPlots() As xySeries, XAxis As xyAxis, YAxis() As xyAxis)
      Dim cs As Chart, oSeries As Series, iPlot As Integer
      Dim sPlot As String, sAlias As String, iAlias As Integer
      'Dim rgTime As Range, rgValues As Range
      
      Set cs = ThisWorkbook.Charts(sCSName)
      
      For Each oSeries In cs.SeriesCollection
          oSeries.Delete
      Next
      
      cs.PlotVisibleOnly = False
      cs.ChartType = xlXYScatterLines
      
      
      With ThisWorkbook.Sheets(&quot;LimeData&quot;)
          
          
          For iPlot = 1 To UBound(asPlots, 1)
              
              cs.SeriesCollection.NewSeries
              cs.SeriesCollection(iPlot).ChartType = xlXYScatterLines
              cs.SeriesCollection(iPlot).Name = asPlots(iPlot).Name
              cs.SeriesCollection(iPlot).XValues = asPlots(iPlot).X
              cs.SeriesCollection(iPlot).values = asPlots(iPlot).Y
              cs.SeriesCollection(iPlot).MarkerStyle = asPlots(iPlot).Markers
              cs.SeriesCollection(iPlot).AxisGroup = asPlots(iPlot).Axis
              cs.SeriesCollection(iPlot).Format.Line.Weight = asPlots(iPlot).Weight
              
          Next iPlot
          
      End With
      
      With cs
          With .Axes(xlCategory)
              .MinimumScale = RangeNominalExtreme(asPlots(1).X, 0)
              .MaximumScale = RangeNominalExtreme(asPlots(1).X, 1)
              .TickLabels.NumberFormat = XAxis.NumberFormat
  
  'Error occurs on the next line
              .ScaleType = XAxis.ScaleType 
  'Run-Time Error '-2147467259' (80004002):
  'Method 'ScaleType' of 'Axis' failed
  
          End With
          .Axes(xlValue, xlPrimary).ScaleType = YAxis(1).ScaleType
          .Axes(xlValue, xlSecondary).ScaleType = YAxis(2).ScaleType
      End With
  End Sub
  </code></pre>