Results 1 to 8 of 8

Thread: Creating charts in Excel with VBA, this code *should* work...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    27

    Creating charts in Excel with VBA, this code *should* work...

    I'm hoping someone has an answer for this:

    VB Code:
    1. Private Sub CmdChart_Click()
    2.  
    3. 'Create the new chart
    4. Dim Newchart As Chart
    5.  
    6. Set Newchart = Charts.Add '(After:=Charts(Charts.Count))
    7.  
    8. 'Change the Name
    9. Newchart.Name = "Pipeline Summary"
    10.  
    11. 'Create a series for the chart
    12.  
    13. Dim TheSeries As Series
    14. Newchart.SeriesCollection.Add _
    15. Source:=Worksheets("Pipeline").Range("K$12:N$50") 'chart data range
    16.  
    17. Set TheSeries = Newchart.SeriesCollection(1)
    18.  
    19. 'Change the chart type
    20. TheSeries.ChartType = xl3DPie
    21. 'Change the series title
    22. TheSeries.Name = "Pipeline Info"
    23.  
    24. 'Data formatting
    25. With TheSeries
    26. .XValues = _
    27.    Worksheets("Pipeline").Range("K$11:N$11") 'chart labels
    28.    .HasDataLabels = True
    29.     .DataLabels.ShowValue = True
    30.     .DataLabels.Font.Italic = True
    31.     .DataLabels.Font.Size = 14
    32. End With
    33.  
    34. 'Modify the legend
    35. With Newchart
    36. .HasLegend = True
    37. .Legend.Font.Size = 14
    38. End With
    39.  
    40. 'modify the 3D view
    41. With Newchart
    42. .HasLegend = True
    43. .Elevation = 45
    44. End With
    45.  
    46. 'format the chart title
    47. With Newchart.ChartTitle
    48. .Font.Bold = True
    49. .Font.Size = 18
    50. .Border.LineStyle = XlLineStyle.xlContinuous
    51. .Border.Weight = XlBorderWeight.xlMedium
    52. End With
    53.  
    54. 'format the plot area
    55. With Newchart.PlotArea
    56. .Interior.Color = RGB(255, 255, 255)
    57. .Border.LineStyle = XlLineStyle.xlLineStyleNone
    58. .Height = 450
    59. .Width = 450
    60. .Top = 75
    61. .Left = 25
    62. End With
    63. End Sub

    The chart itself displays, but only contains the values of K12:K50, instead of everything from K12 - N50. I need it to display the SUM of the values in K12-K50, L12-L50, etc until N12-N50, then display those totals in the chart. Can someone help?

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating charts in Excel with VBA, this code *should* work...

    If the data is not sensitive, or if you have test values, can you post the xls zipped?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    27

    Re: Creating charts in Excel with VBA, this code *should* work...

    sure, here ya go. It uses a database to retrieve the information from. Also, I've noticed null values seem to confuse it a bit :S

    steve
    Attached Files Attached Files

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating charts in Excel with VBA, this code *should* work...

    I have had a look. I do not think that the pie chart is the one you want, and the series seem to be completely uh useless on a piechart.

    I think that for the piechart view to work you need to add all the peoples fees together by section. Then you can make a pie chart on the resulting lines.

    Eg>
    Code:
    Name Commission	Mortgage Fee	Life Fee	Home Insurance Fee
    Bob      100.00			
    Jane      300.00		        599.22	
    Tim       200.00			       200.00
    would become
    Code:
    Total Commission	Mortgage Fee	Life Fee	Home Insurance Fee
    Total 600                                      599.22        200
    Which the pie chart actually means something.

    Perhaps I am missing what you are looking for though sorry!
    Excel intellisense is crap for charting isn't it!

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    27

    Re: Creating charts in Excel with VBA, this code *should* work...

    Ok, if not a pie chart to show the individual values then, what sort of chart to use? I've tried using a bar chart, but the values still dont display properly. If I used a bar chart (or similar) to display all the information, what would the code be? I'd figured out I *don't* need to display the totals of the columns, just the values!

  6. #6
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating charts in Excel with VBA, this code *should* work...

    Perhaps a chart like this? (sheet type 1)

    As I said, I do not know what you are trying to show to managers, but perhaps this is something more like what you want.
    Also - your ranges should be only for those with data, and any nulls should be completed with 0's (find replace?)
    Attached Files Attached Files

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2002
    Posts
    27

    Re: Creating charts in Excel with VBA, this code *should* work...

    We're along the right lines, but it has to be dyanmic (like when another advisor is searched for and their information displayed from the search function). Leave it with me...

  8. #8
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Creating charts in Excel with VBA, this code *should* work...

    Well once you've decided how to display it, you can do the dynamic search and show bit


    Good luck with it, post up if you finish it

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width