Today i have solved the same problem you have this code is in one
Workbook and creates a chart in the active workbook the values are in
column "C".
Sub Grafico()
Dim wb As Workbook
Dim ws As Worksheet
Dim cht As Excel.Chart
Set wb = ActiveWorkbook
'
Set ws = wb.Sheets(1)
'nombra la hoja actual
ws.Name = "TOC"
'Define el rango de trabajo RngC
wb.Names.Add Name:="RngC", RefersToR1C1:= _
"=OFFSET(TOC!R1C3,0,0,COUNTA(TOC!C3))"
Application.ScreenUpdating = False
Set cht = ws.ChartObjects.Add(50, 50, 400, 300).Chart
With cht
.ChartType = xlXYScatterSmoothNoMarkers
..SetSourceData Source:=ws.Range("TOC!RngC"), PlotBy:=xlColumns
.Location Where:=xlLocationAsObject, Name:="TOC"
.HasTitle = True
.ChartTitle.Characters.Text = "TOC en "
With .Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With .Axes(xlValue)
.HasTitle = True
.AxisTitle.Characters.Text = "ppb"
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
.HasLegend = False
With .PlotArea
With .Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
With .Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
End With
End With
Application.ScreenUpdating = True
'Quita las unidades del eje X
ActiveChart.Axes(xlCategory).Select
ActiveChart.ChartArea.Select
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = False
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
End Sub