L
Ludo
Hi,
I have following 'weird' problem.
If i run following code in DEBUG mode, there's no problem at all and
all works fine.
When i run it in REAL TIME (Run time), the code generates a Run-time
error 1004 at following line :
..SetSourceData Source:=ss.Range("A3:A" & lr & "," & I & "3:" & I &
lr), PlotBy:=xlColumns
Whatever i try (adding a wait time before the error generating line,
define ss as Variant) nothing works in Run time.
The only thing i have is an empty chart, no columns at all.
Anyone an idea whats happening and how to solve the problem?
Any help appreciated.
Ludo
I use :
Excel 2003 - SP3
Windows XP Professional Version 2002 - SP2
Sub Add_Chart(Datafilename As String)
'
Const FirstDataCellColumn = 7
Const DataOffset = 7
Const ChartRowIndex = 2
Dim MyOffset As Long
Dim ChartSheet As String
Dim ChartTitle As String
Dim ChartNumber As Integer
Dim LastRow As Long
Dim ChartLeftPositon As Integer
Dim ChartTopPosition As Integer
Dim ChartLeftPosition As Integer
Const ChartTitleFirstColumnPosition = 2
Dim ChartTitleColumn As Long
'
Application.ScreenUpdating = False
ChartLeftPosition = -164
ChartTopPosition = -122
Sheets(UnitFamilyName2).Select
DataSheet = ActiveSheet.Name
MyOffset = FirstDataCellColumn
Dummy2 = 1
Range("G3").Select
ChartTitleColumn = ChartTitleFirstColumnPosition
Set ss = Sheets(ActiveSheet.Name) 'Sheets("DU8X5 -
2010"), ...
lr = ss.Cells(Rows.Count, "B").End(xlUp).Row
lr = Weeknumber(Now()) + 3 ' set to 'from week 1 to actual
week'
Sheets.Add
ActiveSheet.Name = "Chart" & " " & UnitFamilyName2
ChartSheet = ActiveSheet.Name
For Each I In Array("g", "n", "u", "ab", "ai", "ap", "aw", "bd",
"bk", "br", "by", "cf", "cm", "ct", "da", "dh", "do", "dv", "ec",
"ej") 'col g & col n , ...
If Right(Sheets(UnitFamilyName2).Range(I & "3").Offset(-1,
-5).Value, 8) <> "Algemeen" Then
ChartTitle = Sheets(UnitFamilyName2).Range(I & "3").Offset(-1,
-5).Value
Charts.Add
With ActiveChart
.ChartType = xlColumnClusteredI & "3:" & I & lr), PlotBy:=xlColumns ' this line generates the run
time error 1004
.Location Where:=xlLocationAsObject, Name:=ChartSheet
End With
ChartTitleColumn = ChartTitleColumn + DataOffset
ChartNumber = ActiveSheet.Shapes.Count
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "FPY " & ChartTitle & "
HASS"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
"%FPY"
End With
Application.DisplayAlerts = True
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlTop
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
ActiveChart.ChartTitle.Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
End With
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 0.5
.MaximumScale = 1
End With
With ActiveChart.Axes(xlCategory)
.CrossesAt = 1
.TickLabelSpacing = 2
.TickMarkSpacing = 1
.AxisBetweenCategories = True
.ReversePlotOrder = False
End With
ActiveChart.ChartArea.Select
ChartLeftPosition = ChartLeftPosition + (Dummy2 * 20)
ChartTopPosition = ChartTopPosition + (Dummy2 * 20)
ActiveSheet.Shapes(ChartNumber).IncrementLeft
ChartLeftPosition
ActiveSheet.Shapes(ChartNumber).IncrementTop ChartTopPosition
ActiveWindow.Visible = False
Windows("Unit Data Logging.xls").Activate
Range("A1").Select
'prepare to create next chart
Dummy2 = Dummy2 + 1
MyOffset = MyOffset + DataOffset
Else
Dummy = True
End If
If Dummy = True Then Exit For
Next I
Windows("Unit Data Logging.xls").Activate
Range("A1").Select
Sheets("Data Logging").Select
End Sub
I have following 'weird' problem.
If i run following code in DEBUG mode, there's no problem at all and
all works fine.
When i run it in REAL TIME (Run time), the code generates a Run-time
error 1004 at following line :
..SetSourceData Source:=ss.Range("A3:A" & lr & "," & I & "3:" & I &
lr), PlotBy:=xlColumns
Whatever i try (adding a wait time before the error generating line,
define ss as Variant) nothing works in Run time.
The only thing i have is an empty chart, no columns at all.
Anyone an idea whats happening and how to solve the problem?
Any help appreciated.
Ludo
I use :
Excel 2003 - SP3
Windows XP Professional Version 2002 - SP2
Sub Add_Chart(Datafilename As String)
'
Const FirstDataCellColumn = 7
Const DataOffset = 7
Const ChartRowIndex = 2
Dim MyOffset As Long
Dim ChartSheet As String
Dim ChartTitle As String
Dim ChartNumber As Integer
Dim LastRow As Long
Dim ChartLeftPositon As Integer
Dim ChartTopPosition As Integer
Dim ChartLeftPosition As Integer
Const ChartTitleFirstColumnPosition = 2
Dim ChartTitleColumn As Long
'
Application.ScreenUpdating = False
ChartLeftPosition = -164
ChartTopPosition = -122
Sheets(UnitFamilyName2).Select
DataSheet = ActiveSheet.Name
MyOffset = FirstDataCellColumn
Dummy2 = 1
Range("G3").Select
ChartTitleColumn = ChartTitleFirstColumnPosition
Set ss = Sheets(ActiveSheet.Name) 'Sheets("DU8X5 -
2010"), ...
lr = ss.Cells(Rows.Count, "B").End(xlUp).Row
lr = Weeknumber(Now()) + 3 ' set to 'from week 1 to actual
week'
Sheets.Add
ActiveSheet.Name = "Chart" & " " & UnitFamilyName2
ChartSheet = ActiveSheet.Name
For Each I In Array("g", "n", "u", "ab", "ai", "ap", "aw", "bd",
"bk", "br", "by", "cf", "cm", "ct", "da", "dh", "do", "dv", "ec",
"ej") 'col g & col n , ...
If Right(Sheets(UnitFamilyName2).Range(I & "3").Offset(-1,
-5).Value, 8) <> "Algemeen" Then
ChartTitle = Sheets(UnitFamilyName2).Range(I & "3").Offset(-1,
-5).Value
Charts.Add
With ActiveChart
.ChartType = xlColumnClusteredI & "3:" & I & lr), PlotBy:=xlColumns ' this line generates the run
time error 1004
.Location Where:=xlLocationAsObject, Name:=ChartSheet
End With
ChartTitleColumn = ChartTitleColumn + DataOffset
ChartNumber = ActiveSheet.Shapes.Count
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "FPY " & ChartTitle & "
HASS"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Week"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
"%FPY"
End With
Application.DisplayAlerts = True
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlTop
ActiveChart.SeriesCollection(1).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
ActiveChart.ChartTitle.Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
End With
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 0.5
.MaximumScale = 1
End With
With ActiveChart.Axes(xlCategory)
.CrossesAt = 1
.TickLabelSpacing = 2
.TickMarkSpacing = 1
.AxisBetweenCategories = True
.ReversePlotOrder = False
End With
ActiveChart.ChartArea.Select
ChartLeftPosition = ChartLeftPosition + (Dummy2 * 20)
ChartTopPosition = ChartTopPosition + (Dummy2 * 20)
ActiveSheet.Shapes(ChartNumber).IncrementLeft
ChartLeftPosition
ActiveSheet.Shapes(ChartNumber).IncrementTop ChartTopPosition
ActiveWindow.Visible = False
Windows("Unit Data Logging.xls").Activate
Range("A1").Select
'prepare to create next chart
Dummy2 = Dummy2 + 1
MyOffset = MyOffset + DataOffset
Else
Dummy = True
End If
If Dummy = True Then Exit For
Next I
Windows("Unit Data Logging.xls").Activate
Range("A1").Select
Sheets("Data Logging").Select
End Sub