zarathustra
New Member
- Joined
- Jun 8, 2017
- Messages
- 19
I always get an error message when my code reaches the sub CreateChart. Any ideas what goes wrong there? What am I missing?
Code:
Sub q()
Dim DataforPie As Range
Dim Lastrow As Integer
Dim LastColumn As Integer
Dim i As Long
On Error GoTo Help
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
For i = 2 To 4
With Worksheets("Sheet1")
'Set DataforPie = Union(.Range("A1:" & LastColumn & Lastrow), .Range(.Cells(i, 1), .Cellls(i, Replace(Cells(1, LastColumn - 1).Address(False, False), "1", ""))))
Set DataforPie = Union(.Range("A1:G1"), _
.Range(.Cells(i, 1), .Cells(i, 6)))
End With
LPOS = 10
TPOS = 10
Call CreateChart(DataforPie, LPOS, TPOS, 180, 120)
Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
Help:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
MsgBox "Error:Something went wrong!", vbInformation, Important
End Sub
Sub CreateChart(rng, l, t, w, h)
With Worksheets("Sheet2").Shapes. _
AddChart2(332, xlLineMarkers, l, t, w, h).Chart
.SetSourceData Source:=rng
.Axes(xlValue).MinimumScale = 0
.Axes(xlValue).MaximumScale = 100
End With
End Sub
Last edited: