1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
662:
663:
664:
665:
666:
667:
668:
669:
670:
671:
672:
673:
674:
675:
676:
677:
678:
679:
680:
681:
682:
683:
684:
685:
686:
687:
688:
689:
690:
691:
692:
693:
694:
695:
696:
697:
698:
699:
700:
701:
702:
703:
704:
705:
706:
707:
708:
709:
710:
711:
712:
713:
714:
715:
716:
717:
718:
719:
720:
721:
722:
|
'http://msdn.microsoft.com/en-us/library/47zceaw7(VS.80).aspx
Const mc_sglWIDTH As Single = 100
Const mc_sglHEIGHT As Single = 200
Const mc_sglGAP As Single = 20
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24683374.html?cid=1575#a25188926
'===============================
' rory from EE has a list of Color Scheme Values and used these:
' the color Scheme values are stored in the table
' the chart's series object uses Color Index so we have to subtract 7
' from Color SCHEME to get the color's INDEX position in the Excel Color Palette
' the arrow shape object uses the Color Scheme, so we can use these SCHEME values
' DIRECTLY stored in the table
Const mc_sglColorScheme_RED As Single = 10
Const mc_sglColorScheme_BRIGHTGREEN As Single = 11
Const mc_sglColorScheme_BLUE As Single = 12
Const mc_sglColorScheme_DEFAULTBORDERCOLOR As Single = 64
' a type is a basic form of a class
' It's quite a useful way of passing a lot of data to a function/sub
' without having to use lots of arguments,
' because you can define multiple elements for the type
' and then just pass the type across.
' GradeData is declared as Type Double. Thus when it reads in NULL from spreadsheet
' it is converted to 0.
' When processsing row 2, not all buckets get populated,
' therefore, the other mark buckets remain at their intialization of 0 here:
' .Values = Application.Index(objData.GradeData, lngRow, 0)?
Private Type ClassData
ClassName As String
GradeData(1 To 2, 1 To 3) As Double
FillColour(1 To 3) As Long
End Type
Sub AddCharts()
Dim lngLastRow As Long
Dim lngRow As Long
Dim lngCounter As Long
Dim wks As Worksheet
Dim wksCharts As Worksheet
Dim objClassData(1 To 1) As ClassData
Dim sglTop As Single
Dim sglLeft As Single
Dim strClass As String
'this will be used as a table
' spreadsheet is a double dimension array (rows, columns)
' Because varData was Dimmed as a Variant,
' setting it equal to a Range that contains multiple rows and columns
' turns it into a 2D array.
Dim varData As Variant
Application.ScreenUpdating = False
' The Set command associates the name you defined with an object.
' look in the 'Sheets' collection of current workbook for a SPECIFIC worksheet
' The sheet tab would already have to exist since
' 'Sheets' is a collection in VBA
' and "q_for_report" is essentially an index.
Set wks = Sheets("q_for_report")
'Create a new Sheet object and associates it with 'wksCharts'
Set wksCharts = Sheets.Add
sglTop = 25
sglLeft = 25
' calculate last row
' place excel spreadsheet in varData table
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24632162.html
'===================================================================
' varData is being assigned the value of all the cells from A1 to the last row of P.
' So all these cells values are being stored in varData.
' Variants are neat data types in that they can be assigned an array
' without having to declare them as an array.
' As soon as varData was assigned a range of values,
' it became an array, where every element is the value of a cell in that range.
' A1 - header
' Some things in excel (such as charts and pivot tables) take the headers
' in as part of the data to be used as axis or plot-line names
' the method of extracting data the ENTIRE SPREADSHEET'S data in one swoop is below:
' using a RANGE to store the data
' it technically is a user defined 2D array, but it's just a copy of the spreadsheet range.
' variant just stores the values, not the Range itself.
' It is a copy of the values, stored in a 2D array, not an actual Range object,
' instead of a pointer to the data, it is a copy of the data.
' Handy if you want to ensure you don't mess up your original data.
' if it were the actual range object:
' 1) you'd have all the properties of a range object available for use.
' 2) which would mean that changing it's values would change the values on your worksheet.
With wks
lngLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
varData = .Range("A1", .Cells(lngLastRow, "P")).Value
End With
For lngRow = 2 To lngLastRow
' load data into a double dimension array called GradDate
' 2 by 3
' row 1 for Entire Grade's performance
' row 2 for student's performance
strClass = varData(lngRow, 8)
With objClassData(1)
' retrive CourseName
.ClassName = strClass
' retrieve Entire Grade's results for the CourseName (col. 9-11)
.GradeData(1, 1) = varData(lngRow, 9)
.GradeData(1, 2) = varData(lngRow, 10)
.GradeData(1, 3) = varData(lngRow, 11)
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24631533.html
'============
' Prior to Excel 2007, the Excel colour palette is limited to 56 colours
' in a workbook at one time.
' Those are index numbers, which return the colours at those locations in the palette.
' The later code uses those values as SchemeColor values, and also as ColorIndex values
' You need to subtract 7 to convert from SchemeColor to ColorIndex values.
' Note that I used ColorIndex and not Color.
' If you use Color and assign a colour like vbGreen for example,
' what you actually get is the closest colour available from the palette,
' which may or may not resemble the colour you chose!
' Unfortunately the index values bear no relation to the positions on that dialog!
' http://www.mvps.org/dmcritchie/excel/colors.htm
' colors are stored with index numbers from the Excel palette
' not recommended to use keywords like: vbRed
'http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24683772.html
'============================================================================
'http://www.mvps.org/dmcritchie/excel/colors.htm#colorindex
'============================================================================
' Different objects use different properties for color
' to use colors on a chart, we need to use the index position on Excel Color Palette
' .ColorIndex property
' The interior object for a series point uses ColorIndex property
' to use colors on an arrow shape, we need to use the scheme color
' .SchemeColor property
' We populate the objClassData(1).FillColour with Scheme Color
' when we work with chart, we subtract 7 to get its index position
' when we work with arrow, we work directly from objClassData table where
' scheme is stored
' The colors on Palette are not laid out on website in index pos order,
' but laid out vertically in family colors
' when you run your eyes down vertically, you'll see diff. shades of the same
' color family
' SchemeColor is a property of the FormatColor object for ex:
' Forecolor.SchemeColor = nn
' Index values for
' ===================
' The numbers are in order... Just not what you might consider a logical order (to the programmer it was)...
'
' 1 black
' 2 white
' 3 red
' 4 green
' 5 blue
'
' (in the additive color model, all other colors are based on combinations of these)
'
' 6 yellow (red+green in the additive color model)
' 7 pink (red+blue in the additive color model)
' 8 turquoise (blue+green in the additive color model)
'http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24683772.html
'========================
'color additive model
' =======================
' "An additive color model involves light emitted directly from a source
' or illuminant of some sort.
' The additive reproduction process usually uses red, green and blue light
' to produce the other colors."
' Each color is derived from adding certain amounts of Red, Green, or Blue base colors.
' This can be emulated by using the RGB (#, #, #) function.
' Most colors we deal with in life are SUBTRACTIVE colors.
' We see the color that reflects light back to us.
' Adding color lets less light back to our eyes.
' That's why taking all of your paints and mixing them up produces black.
' You keep subtracting color until there is none left.
' (Red, Yellow and Blue are the primary colors in that model)
'On computer monitors, or projectors we use ADDITIVE colors.
' The monitor emits light to our eyes.
' Adding more color on a computer monitor will actually produce white.
' Black is no color, white is all of them.
' Red, Green, and Blue are the primary colors in this model.
' Think of white as mixing up 255 parts red, 255 parts green, and 255 parts blue.
' White has an RGB value of 255,255,255.
' Black, being absence of color, is 0,0,0 (no red green or blue).
.FillColour(1) = mc_sglColorScheme_RED
.FillColour(2) = mc_sglColorScheme_BRIGHTGREEN
.FillColour(3) = mc_sglColorScheme_BLUE
End With
' Debug.Print objClassData(1).GradeData(1, 1)
' Debug.Print objClassData(1).GradeData(1, 2)
' Debug.Print objClassData(1).GradeData(1, 3)
'
' 2nd row: just poulate the column that the student falls under
' with the value of the number of students in the grade that got that value
' the TOTAL student number acts as a creative flag bec. the table is defined as
' double, we cannot store the actual letter value of individual student
' the TOTAL student grade NUMBER for each grade are in columns 9,10,11
' the SINGLE student grade LETTER is in column 7
' this sneaky number flag is used to control the height for all 3 arrows:
' the other 2 values in 2D table are set to 0
' Because only one of them is set via the Select statement,
' only one of the arrows will be visible, as the others will have value = 0,
' thus no height in the chart.
' Remember, it's plotting a second "stack" on your stacked column.
' If you click the arrow in any chart you will see two other data points
' for that 2nd series, both corresponding to the 0 values for the other two grade types.
' Also, because the same number is used for the first stack and the second stack,
' the arrow height is equivalent to that same bar below it.
' Obviously you could change this to a static height if you wanted to.
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24651263.html
' =========================
' So, it is not possible to use the character strings "P", "HP", "H" here
' as the chart needs numeric values to plot.
'deterimne Student's grade for the Course and get assoc Grade Number to use as a flag
Select Case varData(lngRow, 7)
Case "HP"
objClassData(1).GradeData(2, 1) = varData(lngRow, 9)
Case "H"
objClassData(1).GradeData(2, 2) = varData(lngRow, 10)
Case "P"
objClassData(1).GradeData(2, 3) = varData(lngRow, 11)
End Select
'GradeData(1 To 2, 1 To 3) As Double
Dim index1 As Integer
Dim index2 As Integer
Dim index3 As Integer
For index1 = LBound(objClassData) To UBound(objClassData)
For index2 = 1 To _
UBound(objClassData(index1).GradeData)
For index3 = 1 To 3
Debug.Print objClassData(index1).GradeData(index2, index3)
Next
Next
Next
Call CreateChart(objClassData(1), _
wksCharts, _
sglTop, _
sglLeft)
'http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24633101.html
'===================================
' check if we've done 5 charts, if yes create a 2nd row of charts
' increment counter
lngCounter = lngCounter + 1
If lngCounter = 5 Then
' set left back to initial value (25)
sglLeft = 25
' increase Top by chart height, and leave a gap between rows
sglTop = sglTop + mc_sglHEIGHT + mc_sglGAP
lngCounter = 0
Else
sglLeft = sglLeft + mc_sglWIDTH + mc_sglGAP
End If
' FOR THE NEXT CHART: the array gets erased so all the values are reset to 0
Erase objClassData
Next lngRow
Application.ScreenUpdating = True
End Sub
Sub CreateChart(objData As ClassData, _
wksTarget As Worksheet, _
sglTop As Single, _
sglLeft As Single)
' Charts
' ======
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24643624.html
'=======================================
' ObjChart is the parent of Chart, but not in the contains a collection of Charts.
' There is only 1 chart per chartobject.
' you have to define the Object you want to modify,
' then you can specify which properties you want to change,
' including the Chart property and it's subproperties.
' the Chart property has subproperties like Legend, Title
' Chart is just one property of ChartObject,
' Chart also is an Object itself.
'Series
'========
' Most charts actually have series with multiple data points.
' A typical bar chart series has one data point for each category on the X axis.
' The only difference with a stacked column is how the series are plotted
' on top of, bar chart is next to each other.
'It's not really to do with the chart type, but with the data.
' An XY scatter chart for example can have a series with one point or
' a series with thousands of points.
' There are 2 series on the chart. Both series plot on Y AXIS.
' A chart has only one X axis AND Y axis.
' the Y axis can have several series as in to trend line charts.
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24669073.html
'=================================
' or:
' On a line graph if you were plotting say all these students on the same chart
' you could have a line for each student's grade.
' The X-axis being the class and the Y axis being the grade in that class.
' Thus you would have multiple series plotted on the Y-axis,
' and yes you would see overlapping lines.
' the loop is doing is setting the X and Y coordinates for each point in the series.
' The .Values are the Y coordinates,
' and the .XValues are the X coordinates.
' ser.Points is a collection of data points contained in that series.
' You can reference a specific one by using it's index
' ser.Points (lngCol)
' Series 1 = row 1 in array - # of studetns in each category
' Series 2 = row 2 in array - 3 number, one which is non-zero (like a flag)
'So you have two series of #s for your Y-values.
'For instance
'grades in the classes are H:25, HP:20, P: 10, and this student was a P
'You have the two series of numbers
'1) {25,20,10}
'2) {0,0,10}
'A data point is just that, a point on a chart.
' It needs coordinates to be plotted, thus in a stacked bar,
' the X-coordinate is the category, and the Y-coordinate is the value for that series.
'Each on stacked chart box represents a diff. data point
' series may contain multiple data points. Inour case it's just one data point
' The Series are stacked on top of each other.
' series 1 draws the bottom column in each category
' series 2 then stacks above the first.
' we use arrows to: swapped the box marker for an arrow one
' the X axis is the Category axis.
' The Y-axis is the Value axis.
' The values are both the # of students in each category,
' and then also a second series of #s, one of which is non-zero,
' to match which grade level this student fell into.
' One plots the values for the class for H, HP and P.
' The other also has three data points, but only the data for the student
' has a value so there is only one value visible.
' All three data points are actually arrows, you just can't see two of them!
' The second series has two zero values and one 'real' value,
' hence there are three data points for series 2.
' The code simply loops through and sets all of them to display as arrows,
' but the zero value ones have no height on the chart, so you can't see the arrows.
' When code loops through series 2, it replaces the rectangle with an arrow shape
' The zero values are being plotted but because they have zero height, you can't see them.
' This is the same as a standard stacked column chart
' the only difference is that the normal column markers have been replaced with arrows.
' The arrows are being plotted by the chart, not drawn in position by the code.
' drawn probably not the best way to describe it.
' More like substituting the original bar for the graphic of an arrow
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24669303.html
' =============================================
' Clicked the arrow in this chart, and see how the series was selected.
' There are 3 data points in the series containing the arrow.
' The first two have value of 0, so we don't see them
' You will see 3 tiny black squares representing the datapoint.
' the 0 values just show a little square, with no bar.
' you could actually then click and select those specific data points if you wanted.
Dim objChtObj As ChartObject
Dim cht As Chart
Dim ser As Series
Dim lngRow As Long
Dim lngCol As Long
With wksTarget
' create container for Chart
Set objChtObj = .ChartObjects.Add(sglLeft, _
sglTop, _
mc_sglWIDTH, _
mc_sglHEIGHT)
Set cht = objChtObj.Chart
With cht
'http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24643664.html
'===========================
'regular stacked
' 100% stacked is: xlColumnStacked100 - all bars in stack represent the whole of 1005
.ChartType = xlColumnStacked
For lngRow = 1 To 2
Set ser = .SeriesCollection.NewSeries
With ser
' EXTRACT array to create Y VALUES, plot the data points
' This is using the INDEX function to return an item
' from an (multi-dimensional) array.
' In this case the array is objData.GradeData,
' which previously stored the grades.
' It's returning the lngRow row
' and because 0 was specified as the column,
' it should return all columns for the lngRow(th) row.
' In other words, it's returning an array of grades
' for the lngRow(th) class.
' making use of the INDEX function to go against a user defined
' double dimension array INSTEAD of a spreadsheet
' so retrieving ONE row and it's column(s) in a spreadsheet
' This line sets the values to be plotted, which "builds" the data bars.
' It is making the coordinates.
' The chart draws the bars from these coordinates
' This is returning an array (length 3).
' Thus there are 3 Y-coordinates, which when put together with
' the 3 X-coordinates
' .XValues = ....
' you get the 3 data points in the series.
' For the second series with arrows,
' it's the same as the first series, but the array returned to .Values
' will contain two 0s and one non-zero value.
' The code doesn't have to "position" the arrow per-se,
' as it is just replacing the bar in the chart for the second series
' with a picture of an arrow. It already knows where that data point is.
'===============================================
' For graphing data points
' series/row = 1 for student group
' series/row = 2 specific student's grade for the class
' by default when the data points "draw", they draw as bars
' so one bar will stack on top of the other,
' meaning one series will stack on top of the other
' later in code we will replace the bar for series/row 2 with an arrow
'===============================================
.Values = Application.Index(objData.GradeData, lngRow, 0)
' EXTRACT array to create X categories- the type of grade received
.XValues = Array("HP", "H", "P")
' X,Y = Coordindate called a DATA point
' for main data, just colour points
' A Point is a data point in a series.
' In this case you have 3 series, each with only 1 point
' (the number of students in that class with a certain grade).
'========================================
' For coloring each series
' series/row = 1 - bars use Index pos for color
' series/row = 2 - arrows use Scheme color
' Bars graph all 3 categories in series
' Arrows draw above all 3 categories in series
' -but-
' Only the Arrow with a grade "draws"
' The other arrow stay hidden bec the grade is 0, so the height draws
' at 0
If lngRow = 1 Then
For lngCol = 1 To 3
' Setting the ColorIndex of the point.
' The ColorIndex is associated with the color palette of Excel.
' All the -7 is doing is changing which color shows up for each series.
' Just to add, the -7 is there because there is a difference of 7
' for the same colour between SchemeColor and Colorindex.
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24644519.html
'============================
' reset the colorIndex for each series.
' The 7, because the SchemeColor indexes don't match the ColorIndex indexes.
' They are offset by 7 positions.
' So the color indexes 3, 4, 5 (Red, Bright Green, Blue)
' in the color palette are:
' scheme colors 10, 11, 12 respectively.
' if you really want to make sure you are using the same color
' it's best to use the .Color property instead of the .ColorIndex
' property and then set the color via RGB.
'This isn't reliant on the palette at all.
' To set color of bar for entire student group
ser.Points(lngCol).Interior.ColorIndex = _
objData.FillColour(lngCol) - 7
Next lngCol
Else
' for arrow data, add arrow and colour
For lngCol = 1 To 3
Call AddArrowToPoint(ser.Points(lngCol), _
objData.FillColour(lngCol))
Next lngCol
End If
End With
Next lngRow
' With .Axes(xlValue)
' .HasTitle = True
' .AxisTitle.Characters.Text = "Percentage of Students"
' End With
' set gap width
.ChartGroups(1).GapWidth = 0
.HasLegend = False
' add title using class name
.HasTitle = True
With .ChartTitle
.Text = objData.ClassName
.AutoScaleFont = False
.Font.Size = 9
End With
End With
End With
End Sub
Sub AddArrowToPoint(pt As Point, _
lngSchemeColour As Long)
Dim shpArrow As Shape
Dim dblLeft As Double
Dim dblTop As Double
Dim dblWidth As Double
Dim dblHeight As Double
dblLeft = 92.25
dblTop = 191.25
dblWidth = 30.75
dblHeight = 27.75
'http://msdn.microsoft.com/en-us/library/aa221788(office.11).aspx
'================================================================
Set shpArrow = ActiveSheet.Shapes.AddShape(msoShapeDownArrow, _
dblLeft, _
dblTop, _
dblWidth, _
dblHeight)
' http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24683374.html?cid=1575#a25188926
'===============================
' rory from EE has a list of Color Scheme Values and used these:
' the color Scheme values are stored in the table
' the chart's series object uses Color Index so we have to subtract 7
' from Color SCHEME to get the color's INDEX position in the Excel Color Palette
' the arrow shape object uses the Color Scheme, so we can use these SCHEME values
' DIRECTLY stored in the table
With shpArrow
With .Fill
.Visible = msoTrue
.Solid
.ForeColor.SchemeColor = lngSchemeColour
.Transparency = 0#
End With
With .Line
.Weight = 0.75
.DashStyle = msoLineSolid
.Style = msoLineSingle
.Transparency = 0#
.Visible = msoTrue
' for fore/back color can use either SchemeColor or RGB
.ForeColor.SchemeColor = mc_sglColorScheme_DEFAULTBORDERCOLOR
.BackColor.RGB = RGB(255, 255, 255)
End With
.CopyPicture
pt.Paste
End With
Application.CutCopyMode = False
shpArrow.Delete
End Sub
'========================================
' how to change axis properties with VBA
'========================================
' xlValue = Y axis that plots data values (which equals numeric value 2)
' xlCategory = X axis (which equals numeric value 1)
'so .Axes(2) is the same as .Axes(xlValue)
' .Axes(1) is equivalent to .Axes(xlCategory)
'Yes, once the chart is created you can alter the Y-axis with code like the following
'
' With ActiveChart.Axes(xlValue)
' .MinimumScaleIsAuto = True
' .MaximumScale = 7
' .MinorUnit = 0.5
' .MajorUnit = 1
' .Crosses = xlAutomatic
' .ReversePlotOrder = False
' .ScaleType = xlLinear
' .DisplayUnit = xlNone
' End With
|