+ Reply to Thread
Results 1 to 4 of 4

Chart Title from Dynamic Range Issue

Hybrid View

a2excel Chart Title from Dynamic... 07-09-2012, 01:49 PM
Ace_XL Re: Chart Title from Dynamic... 07-09-2012, 03:57 PM
a2excel Re: Chart Title from Dynamic... 07-09-2012, 04:02 PM
Andy Pope Re: Chart Title from Dynamic... 07-10-2012, 03:41 AM
  1. #1
    Registered User
    Join Date
    07-09-2012
    Location
    Ann Arbor, MI, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Chart Title from Dynamic Range Issue

    My first post and I'm a novice user so please excuse any naivete on my part.

    I'm writing (using) some code to parse out multiple sheets that will in turn chart mulitple data sets. I can't, for the life of me, get the charts to show the dynamic titles and I'm not even sure if there's a way to make it happen. Everything else works, but the titles, which I would like to use a range of 3 cells, starting with A2:C2 on each sheet. I'm working Excel 07 but can get it on '10 if need be. Here's the code - thanks for any help you may have!

     'This is the graphing portion
                            Set rng4 = Range("A2:C2") 'the XXX plant that makes sure we're not overloading data
                            Set rng3 = Range("D1:O4") 'this is the range of the graph data - no labels included
                            t = 0
                            
                        While rng4.Value <> ""
                        
                       
                        
            
                            With ActiveSheet.ChartObjects.Add _
                                      (Left:=100, Width:=375, Top:=t, Height:=225)
                                      .Chart.SetSourceData Source:=rng3
                                      .Chart.ChartType = xlXYScatterLines
                                      .Chart.HasTitle = True
                                      .Chart.ChartTitle.Characters.Text = Range("rng4")
                                      
                                      
                            End With
                            Set rng4 = rng4.Offset(4)
                            Set rng3 = rng3.Offset(4, 0)
                            t = t + 225
                        Wend

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Chart Title from Dynamic Range Issue

    Not sure if chart titles can be referenced to an array of multiple cells (A2:C2). Combine your results in a single cell and use single cell referncing only
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Registered User
    Join Date
    07-09-2012
    Location
    Ann Arbor, MI, USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Chart Title from Dynamic Range Issue

    Thanks for the reply - I fixed it by ditching the range reference and converting the whole thing to a string and looping it for my sheet.

    'graphing portion
                            
                            Set rng4 = Range("A2") 'the XXX plant that makes sure we're not overloading data
                            Set rng3 = Range("D1:O4") 'this is the range of the graph data - no labels included
                            
                            t = 0 'sets the start of the graphs at the top of the spreadsheet
                            x = 0 'using r1c1 language to get the title right
                            x2 = 0 'same thing for middle part of string
                            x3 = 0 'same thing for last part of string
                            
                            While rng4.Value <> "" 'makes sure there is something to stop the loop
                                
                                Set Chartsheet = ActiveSheet 'not sure if this is necessary
                                tempstr = Chartsheet.Cells(x + 2, 1) & " " & Chartsheet.Cells(x2 + 2, 2) & " " & Chartsheet.Cells(x3 + 2, 3)
                        
                
                                With Chartsheet.ChartObjects.Add _
                                      (Left:=100, Width:=375, Top:=t, Height:=225)
                                      .Chart.SetSourceData Source:=rng3
                                      .Chart.ChartType = xlXYScatterLines
                                      .Chart.HasTitle = True
                                      .Chart.ChartTitle.Text = tempstr
                                        x = x + 4
                                        x2 = x2 + 4
                                        x3 = x3 + 4
                                      
                                End With
                                
                                Set rng4 = rng4.Offset(4)
                                Set rng3 = rng3.Offset(4, 0)
                                t = t + 225
                            
                            Wend
    Pretty amateurish, but it works. Thanks again for the quick reply!

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Chart Title from Dynamic Range Issue

    activechart.ChartTitle.Formula = "='" & Activesheet.name & "'!A2:C2"
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.6.0 RC 1