Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. Option Explicit
  2. Dim isChart As Boolean ' True = chart added; False = chart deleted
  3. Dim isRent As Boolean ' True = column clustered; False = line markers
  4. Dim isBuy As Boolean ' True = column clustered; False = line markers
  5. Dim isTitle As Boolean ' True = visible; False = hide
  6. Dim isLegend As Boolean ' True = visible; False = hide
  7.  
  8. ' 2. Implement click event handler for the Chart button. (+20pts)
  9. Sub ButtonChart_Click()
  10.  
  11. Dim chtObject As ChartObject
  12. Dim cht As Chart
  13. Dim sc As SeriesCollection
  14. Dim ser As Series
  15. Dim topCell As Range
  16.  
  17. If isChart Then Sheet2.ChartObjects.Delete
  18.  
  19. Set chtObject = ThisWorkbook.Worksheets("Chart").ChartObjects.Add(Range("D3").Left, Range("D3").Top, Range("D3:M20").Width, Range("M3:M20").Height)
  20. chtObject.Name = "Monthly"
  21. isChart = True
  22.  
  23. Set cht = chtObject.Chart
  24. Set topCell = Range("A1")
  25.  
  26. With cht
  27. .HasLegend = True
  28. .HasTitle = True
  29. .ChartTitle.Text = "Monthly Average"
  30. Set sc = .SeriesCollection
  31. Set ser = sc.NewSeries
  32. With ser
  33. .Name = topCell.Offset(1, 1)
  34. .XValues = Range(topCell.Offset(2, 0), topCell.Offset(2, 0).End(xlDown))
  35. .Values = Range(topCell.Offset(2, 1), topCell.Offset(2, 1).End(xlDown))
  36. .ChartType = xlLineMarkers
  37. End With
  38. Set ser = sc.NewSeries
  39. With ser
  40. .Name = topCell.Offset(1, 2)
  41. .Values = Range(topCell.Offset(2, 2), topCell.Offset(2, 2).End(xlDown))
  42. .ChartType = xlColumnClustered
  43. .AxisGroup = xlSecondary
  44. End With
  45. End With
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement