+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    using vb to create charts over multiple worksheets

    i wonder if anyone can help.

    i have sheet1 called Data. and on here i have ever growing tables of data for our clients.

    i would like the following sheets to contain graphs for each client.

    so is there a vba which i could use that picks out a clients data range and creates a graph and drops it into their own worksheet?

    thanks for your help

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: using vb to create charts over multiple worksheets

    More than likely but we would need more information before being able to provide any more.

    Have you tried using the macro recorder?

    Do you need multiple charts? Perhaps 1 chart with the data filtered by client would suffice.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    Re: using vb to create charts over multiple worksheets

    ok. so i could maybe have 1 chart and somehow filter the data for the client i wish to see?


    you'll have a better idea of my request if i upload the spreadsheet....
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    Re: using vb to create charts over multiple worksheets

    you'll notice that i have a (just about working) code for printing all the charts to PDFs... if i was to use 1 graph and autofilter, is there still a way to print to pdf for all my clients individually?

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: using vb to create charts over multiple worksheets

    See attached

    This code produces a chart for each client.
    The sheet name is based on Policy number for avoid duplicates in names.
    If the sheet for a policy exists it will update the chart. If not a new sheet is created based on the ChtTemplate sheet.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    Re: using vb to create charts over multiple worksheets

    that is fantastic... exactly what i needed.

    there are 2 other things i'd like aswell on these generated sheets, i wonder if it can be incorporated into the same action.

    1. a table of the same data in the chart
    2. our company logo in the top left of the sheet.

    is this possible at a click of a button too?

    EDIT: can you confirm that when i update charts (with the code you provided to me above) it will resize the chart if necessary?
    Last edited by mania112; 05-31-2009 at 11:58 AM.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: using vb to create charts over multiple worksheets

    Data is now copied to local sheet and chart uses local data.

    You can stick you logo on the chart template sheet.

    I have already placed a button on the data sheet.

    What do you mean by resize?
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  8. #8
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    Re: using vb to create charts over multiple worksheets

    by resize i mean 2 things.

    the data is our clients funds, so if they're going down, we'd like to make sure the line isnt too steep... so my 'trick' usually is to increase the data range, so the line is never looks too dramatic.

    the second question re: resizing is too automatically increasing the possibility of future data... so in this case can we say data in 2010 will be shown on the graph?

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: using vb to create charts over multiple worksheets

    The macro updates the sheet, or creates if not already existing, with complete data from Data worksheet.

    Yeah that first point is a data distortion so I let you workout how you do that.
    If you really don't what you clients to see the trend displayed by the chart why give them a chart just use a table of numbers?
    Cheers
    Andy
    www.andypope.info

  10. #10
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    Re: using vb to create charts over multiple worksheets

    it's a question i ask myself! I just do what i'm told

    thanks for all your help, you've given me a great foundation to build on there and saved me a week a month preparing all these (there are many other spreadsheets like this one).

    I do have 1 very minor question:- how can i set every single sheet as landscape?

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: using vb to create charts over multiple worksheets

    If you format the ChtTemplate sheet then run the macro the newly created sheets should retain the formatting, including page layout.
    Cheers
    Andy
    www.andypope.info

  12. #12
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    Re: using vb to create charts over multiple worksheets

    2 more things before i leave you alone!

    1. I see how to move the table to a different cell (and how to find data again to make the graph) but is there a way to make the table vertical down a column rather than along a row. I would like the end result to be a graph and table side by side in landscape view.

    2. Can you show me how to put the 'original transfer value' in a cell on the clients' sheet too - for arguements sake D32 in each sheet.

    Thanks again for this

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: using vb to create charts over multiple worksheets

    Code:
    Sub CreateClientCharts()
    
        Dim shtData As Worksheet
        Dim rngData As Range
        Dim shtPolicy As Worksheet
        Dim rngHeader As Range
        Dim rngRow As Range
        Dim rngLabels As Range
        
        On Error Resume Next
        
        ' get Data
        Set shtData = Worksheets("Data")
        Set rngData = shtData.Range("A7").CurrentRegion
        Set rngHeader = rngData.Rows(1)
        Set rngData = rngData.Offset(1, 0).Resize(rngData.Rows.Count - 1, rngData.Columns.Count)
        Set rngLabels = shtData.Range(rngHeader.Cells(1, 12), rngHeader.Cells(1, rngHeader.Columns.Count))
        
        For Each rngRow In rngData.Rows
            ' check whether to create report
            If rngRow.Cells(1, 11).Value = "Y" Then
                Set shtPolicy = m_GetPolicySheet(rngRow.Cells(1, 5).Value)
                
                ' copy over labels and data
                rngLabels.Copy
                shtPolicy.Range("A1").PasteSpecial , , , True
                shtData.Range(rngRow.Cells(1, 12), rngRow.Cells(1, rngRow.Columns.Count)).Copy
                shtPolicy.Range("B1").PasteSpecial , , , True
                
                rngRow.Cells(1, 6).Copy shtPolicy.Range("D32")
                
                With shtPolicy.ChartObjects(1).Chart
                    .ChartTitle.Text = Left(rngRow.Cells(1, 2).Value, 1) & " " & rngRow.Cells(1, 1).Value & " " & _
                                       rngRow.Cells(1, 4) & " " & rngRow.Cells(1, 5).Value
                    With .SeriesCollection(1)
                        .Values = shtPolicy.Range("B1").Resize(rngLabels.Columns.Count, 1)
                        .XValues = shtPolicy.Range("A1").Resize(rngLabels.Columns.Count, 1)
                        .Name = shtPolicy.Name
                    End With
                End With
            End If
        Next
        
    End Sub
    Cheers
    Andy
    www.andypope.info

  14. #14
    Registered User
    Join Date
    05-26-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    94

    Re: using vb to create charts over multiple worksheets

    no worries
    Last edited by mania112; 06-01-2009 at 09:59 AM. Reason: found the problem!

  15. #15
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: using vb to create charts over multiple worksheets

    The function accepts as it's argument the Policy Number. Previously that was located in column E of the row being processed. Is that still the case?

    Also the value in column E is used as the sheet name so should be a unique value and one that is valid as a tab name. No special characters and less the 31 characters.
    Cheers
    Andy
    www.andypope.info

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0