ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA charting Question (https://www.excelbanter.com/excel-programming/282514-re-vba-charting-question.html)

Tom Ogilvy

VBA charting Question
 
the string xlDiamond is meaningless. xlDiamond is a constant defined to
mean

? xlDiamond
2

the number 2.

so you would need to pass the value 2 to MarkerSTyle

..MarkerStyle = 2

or MarkertypeArray(1) = xlDiamond
or MarkertypeArray(1) = 2

then
i = 1
..MarkerStyle = MarkertypeArray(i)

--
Regards,
Tom Ogilvy


Gromit wrote in message
...

Hi,

I'm trying to write some code to create a chart and format the series.
Things were all going well until I ran into the problem of adding a
different MarkerStyle to each series. I have a group of cells in a
worksheet (cells 12,15) to (cells 17,15) with the markertype names
listed (e.g. xlDiamond etc). I first put these into an array
MarkerTypeArray(i) using a For Next Loop which the watch window tells
me was successful.

However, when it comes to putting the names from the array into the
chart series, things don't work out, and I can't figure out why. I'm
using the code: (With series) .MarkerStyle = MarkerTypeArray(i)


When I hardwire .MarkerStyle = xlDiamond, it works. And I know that
MarkerTypeArray(i) contains the string 'xlDiamond'. So why doesn't
MarkerStyle = MarkerTypeArray(i) work?

Thanks in advance. The full code is below.

Graham


Sub AddChart()
Dim myChtObj As ChartObject
Dim MyNewSrs As Series
Dim MarkerTypeArray(12 To 17)
Dim i As Integer

For i = 12 To 17
MarkerTypeArray(i) = Workbooks("B19.xls").Sheets("Summary").Cells(i,
15)
Next i


Workbooks("B19.xls").Sheets("Summary").ChartObject s.Delete

Set myChtObj =
Workbooks("B19.xls").Sheets("Summary").ChartObject s.Add _
(Left:=100, Width:=500, Top:=75, Height:=400)
myChtObj.Chart.ChartType = xlLineMarkers
myChtObj.Chart.SetSourceData Source:=Sheets("Summary").Range("A1")

For i = 12 To 17
Set MyNewSrs = myChtObj.Chart.SeriesCollection.NewSeries
MsgBox MarkerTypeArray(i)
With MyNewSrs
Name = Cells(i, 13).Value
Values = Cells(i, 14).Value
XValues = Array(6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5)
MarkerStyle = MarkerTypeArray(i) '******** GIVES ERROR
Border.Weight = xlThin
Border.LineStyle = xlNone
MarkerBackgroundColorIndex = 2
MarkerForegroundColorIndex = 11
Smooth = False
MarkerSize = 5
Shadow = False
End With

Next i


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/




Gromit

VBA charting Question
 

Much appreciated!


Graha

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com



All times are GMT +1. The time now is 05:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com