title: defining vba chart location
body: <p>I'm new to vba and am trying to position a vba chart on an excel page.  Below is the code.  If I replace:</p>
  
  <pre><code>Set c = c.Location(Where:=xlLocationAsObject, Name:=chLoc.Parent.Name)
  </code></pre>
  
  <p>with </p>
  
  <pre><code>Set c = c.Location(Where:=xlLocationAsObject, Name:="Sheet1")
  </code></pre>
  
  <p>then the code works.  Otherwise I get 
  'error 1004   Method 'Range' of Object' _Worksheet failed' 
  and the error occurs on line:</p>
  
  <pre><code>   Set chLoc = sh2.Range(sh2.[a1:g10])
  </code></pre>
  
  <p>Here is the code - thanks and if you have good resource for vba charts I would appreciate any direction:</p>
  
  <pre><code>Sub Chart()
  
      Dim sh1 As Worksheet
      Dim sh2 As Worksheet
  
      Dim xaxis As Range
      Dim yaxis As Range
  
      Set sh1 = ActiveWorkbook.Sheets("Spon Email Performance Graph")
      Set sh2 = ActiveWorkbook.Sheets("Graphs")
  
      Set xaxis = sh1.Range(sh1.[b15], sh1.[b15].End(xlDown))
      Set yaxis = sh1.Range(sh1.[g15], sh1.[g15].End(xlDown))
  
      Dim chLoc As Range
      Set chLoc = sh2.Range(sh2.[a1:g10])
  
      ' Worksheets("Graphs").ChartObjects.Delete
  
      Dim c As Chart
      Set c = Charts.Add
      Set c = c.Location(Where:=xlLocationAsObject, Name:=chLoc.Parent.Name)
      With c
          .ChartType = xlColumnClustered
          ' set other chart properties
  
      End With
  
      Dim s As Series
      Set s = c.SeriesCollection.NewSeries
      With s
          .Values = yaxis
          .XValues = xaxis
          ' set other series properties
      End With
  
  
  End Sub
  </code></pre>