Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to create charts for repeatative columns in a sheet. I wrote the following code:
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("500Ml").Range("B + CStr(i + 3):AB + CStr(i + 6)").Select, PlotBy:=xlRows
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Total!R3C3:R3C28"
ActiveChart.SeriesCollection(2).XValues = "=Total!R3C3:R3C28"
ActiveChart.SeriesCollection(3).XValues = "=Total!R3C3:R3C28"
ActiveChart.SeriesCollection(4).XValues = "=Total!R3C3:R3C28"
ActiveChart.Location Where:=xlLocationAsObject, Name:="Total"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = Sheet4.Cells((CStr(i) - 1) * 6 + 4, 1) + "-500 ml"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
The third line starting with "ActiveChart.SetSourceData Source...." gives the error message: Run-time error 1004. Application-defined or object-defined error. I checked the microsoft support link for this error but it didn't solve my problem.http://support.microsoft.com/default.aspx?kbid=159957
Please help me out. I have a deadline to meet, soon....:(

Where do you come from, Fortran/Pascal backgound? Your SetSourceData line looks a heck of a lot like Pascal...so [BUZZER] it aint vba.
it should look like this:
ActiveChart.SetSourceData Sheets("500Ml").Range("B" & CStr(i + 3) & ":AB" & CStr(i + 6)).Select, xlRows
Here are the problems:
1) your strings in vb do not parse through like Perl does. So you must enclose the strings within double quotes, not the commands too.
2) VB uses the ampersand to concatenate strings, not the plus sign (most other languages do use the plus sign) so all your + need to be &
3) When you send variables through a function/procedure call in vb, you do NOT include the variable names followed by := (very pascalish) so your calls freak out when you use them like this.I did not run the program, so i don't know what else you might encounter, but this should help you start. Let me know if this helps at all
Later,
Chi Happens

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |