Results 1 to 18 of 18

Thread: Excel VBA Graph[urgent]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Excel VBA Graph[urgent]

    I did manually create a graph on a sheet called "Graph" according to a sheet called "Project Manager". Each project has a graph with their detail to show their performance.

    IN VBA part, I did create a button to add project manager to add and delete the Project Manager. Now the problems is, when i delete a project manager, the Graph do not intelligent enough to update the source in the graph to appropriate Project Manager, now all the Graph information is wrong because they are refering to address, not to correct Project Manager.

    Is there anyway to solve this problems? Thanks for helping.

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

    Re: Excel VBA Graph[urgent]

    If you do not need to have lots of graphs, perhaps a look up list of project managers on one sheet, with appropriate ranges, and one graph with a list (validation?) on a cell to choose who to view.

    As to your problem, if you flowchart how your sheet reacts when you delete a project manager, how are you going to choose the source for the data?

    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
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    ya, correct, if i delete a project manager, how intelligent the VBA would be to help me to choose the appropriate source of date, you get what i mean?

    How to look up in the Graph and choosing the correct Project Manager

    What should i put in Souce of Data in the VBA to able me to choose the source in another sheet and return whole row back to the source of data in Graph.

    Let's say the graph is in Graph Sheet, the project manager is in PM Chart, row A, and the source chart will be in PM Chart row C to row N which is from january to December performance result.
    Last edited by danielngoo; Jun 5th, 2005 at 09:17 PM.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    Could anyone please help me? Urgent....

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Graph[urgent]

    i did a macro to update a graph, so that as more data was added it would look for the end of the data and reset the chart data,

    if that can be any help to you i gan get you that code

    pete

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    that would be nice if you post up the code. ... thanks westconn1

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Graph[urgent]

    VB Code:
    1. Private Sub Chart_Activate()
    2. Dim d As Date, d1 As Date
    3.  
    4. If actve Then actve = False: Exit Sub
    5. actve = True
    6.  
    7.      Worksheets("Sheet1").Visible = False
    8.      d = Format(DateAdd("m", 1, Date), "mm/yyyy")
    9.      d1 = Format(DateAdd("yyyy", -1, Date), "mm/yyyy")
    10.      Worksheets("Sheet1").Activate
    11.      ActiveCell.SpecialCells(xlLastCell).Select
    12.     ActiveCell.Offset(0, -1).Select
    13.  
    14.    Do While ActiveCell.Text = ""
    15.    ActiveCell.Offset(-1, 0).Select
    16.    Loop
    17.    ac = "A1:" & ActiveCell.Address
    18. Worksheets("Sheet1").Visible = True
    19. Charts(1).Activate
    20.     ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("a1:" & ac)
    21.     With ActiveChart.Axes(xlCategory)
    22.         .MinimumScale = d1
    23.         .MaximumScale = d
    24.  
    25.     End With
    26. End Sub

    this may give you some clues, i am sure i could manage to improve on this a lot now, to when i did it some years ago, but hav no real need to do so. and i had to stop this from being recursive, actve was declared at form level

    pete

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    thsi is able to change one graph or many graphs?

    because at PM CHART sheet, there are many diffrernt graphs indicating diffrent managers ..

    from what i understand from the code, it chooses the active chart, right ?

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Graph[urgent]

    this is just a sample i did some time ago, for a single graph on it's own sheet, some of the code should be adaptable to your applicaion

    pete

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    For a single graph i think can be used, but my problem now is how to choose a single appropriate Graph from many Graphs then to another Graphs in a sheet ?

  11. #11

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    or i am thinking of another alternative, in the Source Data of graph, what is the correct command to LOOKUP ?

    Example, i want to search "Daniel" in 'Family - Member' sheet B10:B30, return value of 'Family - Member' sheet D10:O30,

    That means when i finished searching Daniel and found it, it will return row data back to another graph sheet.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    anyone knows whether can LOOKUP function can be used in Graph source data ?

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Graph[urgent]

    That means when i finished searching Daniel and found it, it will return row data back to another graph sheet.
    that is basically what the code i posted does, finds the end of the data, then returns that row to the source for the graph, but if you want to do it for several graphs you have to do it for each.

    pete

  14. #14

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    What i mean is in the Data Souce itself in the template, it's not the Visual Basic Code

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Graph[urgent]

    i don't understand what you are trying to do now, i thought you wanted the graphs to load depending on the data

    post your spreadsheet if you want me to have a look, mark which part is not working for you

    pete

  16. #16

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    16

    Re: Excel VBA Graph[urgent]

    ok, forget all my problems previously.

    If i want to create a graph, in the source of data, can i use LOOKUP?
    Name: ="Demand FTE"
    Values: = LOOKUP ( Can look up being use here)

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel VBA Graph[urgent]

    if you put you chart data in to named ranges this will work to add new charts, it could be adapted to change data range on existing as well
    VB Code:
    1. Dim n As Name, rng As Range, i As Integer
    2.  
    3. For Each n In Names
    4.     Application.Goto Reference:=n.Name
    5.    
    6.     Set rng = Application.Selection
    7.    
    8.     Charts.Add
    9.     ActiveChart.ChartType = xlColumnClustered
    10.     ActiveChart.SetSourceData Source:=rng 'Sheets("Sheet1").Range("B5:B13")
    11.     ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    12. s = Right(ActiveChart.Name, Len(ActiveChart.Name) - 7)
    13.         ActiveSheet.Shapes(s).IncrementTop i * 220
    14.     i = i + 1
    15. Next

    if you need more help, i think i woould need to see a sample of your workbook
    sometimes that is so much easier

    pete

  18. #18
    Lively Member
    Join Date
    May 2005
    Location
    derby, uk
    Posts
    83

    Re: Excel VBA Graph[urgent]

    You *may* not even need VBA for this, while you cannot use functions directly within the graph formula, you can use named ranges.

    big 'gotcha' ALL references in the graph formula MUST be exact, e.g. $A$1 not A1. thus any formula MUST return absolute references.

    Hint: build the formula up in stages, if your data is in multiple sheets, have one cell on a page which can be set to be equal to the sheet name for the data you require (you can now include this in the function to specify the formula).

    All you really need to do, is locate the start of your data, and work out how long the range is. now for the complex bit. The formula to actually build each range is nasty, and should be built on a worksheet, since once in the named range box its virtually impossible to edit it (since using the cursor keys causes trouble).

    I can't remember the exact formula, but its based on a mix of MATCH(), OFFSET() and ADDRESS(). theres no problems using a VLOOKUP() or anything esle to throw a parameter into the mix.

    start small. Hard code your range to a named range and plot the graph from that.

    then modify the formula to use ADDRESS() with coded parameters, then replace these parameters with forumlas. the idea is that when you make a mistake (you will, its nasty) you can work out where.

    Its worth having the formula (which will return an array) defined in a cell, then have another cell with ROWS() pointing to the named range to monitor how its working.

    With a bit of work you can have ALL your charts controlled by a few pick lists.

    e.g. a start point, and how many days to look back controlling you X-Axis, and another box picking which page you look at. Now you can apply your formatting once.

    for multiple charts at once, well define the ranges more than once (once for each graph) and either have multiple control ranges or hard code some parts.

    I'll have to dig the example sheet up.

    (I got sick of updating about 50 ranges each week so spent two days head scratching this one out - it REALLY SHOULD be in the help file, or failing that allow the charting engine to use relative references like everything else can)

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