+ Reply to Thread
Results 1 to 4 of 4

Automate chart range dependent upon data present

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    5

    Automate chart range dependent upon data present

    Hi,

    I've got some data that is tracking cases until the end of the next year on a monthly basis. Each month that this is run, the number of months reduces by one, causing me to re-source my chart changing its range to one column less.

    I'm running VBA for the file anyway, so would like to add something in to alter the range of my chart to not show blank columns when those months are no longer populated.

    Unfortunately I can't just do a xlRight to get the range as all possible columns (upto 23 months) are populated with VLookUp values, however I only take the valid values into the chart.

    Using R1C1 I can get the appropriate width of the table, but unfortunately the chart isn't just one block of data, the headings are on row 10 with the contents on rows 12-26 (I can't change this layout).

    How would I go about setting a VBA job to change the chart range to show just the valid fields?

    Many thanks

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Automate chart range dependent upon data present

    You could put #N/A in the data used for the X axle when the display must not be done: See with a formula versus the time frame used

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Automate chart range dependent upon data present

    Maybe post the code where you have that is creating the chart? or is the chart already there and the code is just populating data?

    I personally use something like this to create chart:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-15-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Automate chart range dependent upon data present

    After much messing with code I think I've finally got what I was after.


    Sub Update_Monthly_DTV_Chart()

    Sheets("Maturity - DTV Monthly").Select

    Dim Cols As Integer
    Dim Rng1 As Range, Rng2 As Range
    Dim NewRng As Range

    Cols = ActiveWorkbook.Sheets("Maturity - DTV Monthly").Cells(3, 15).Value - 2

    With ActiveWorkbook.Sheets("Maturity - DTV Monthly")
    Set Rng1 = .Range(Cells(10, 6), Cells(10, Cols))
    Set Rng2 = .Range(Cells(12, 6), Cells(26, Cols))

    Set NewRng = .Range(Rng1.Address & "," & Rng2.Address)
    End With

    Sheets("Maturity Charts").Select
    ActiveSheet.ChartObjects("Chart 6").Activate
    ActiveChart.ChartArea.Select
    ActiveChart.SetSourceData Source:=Sheets("Maturity - DTV Monthly").Range(NewRng.Address)
    End Sub

    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Auto Hiding rows based on range/data present or not present.
    By raze in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 02-10-2013, 11:27 AM
  2. Automate data on chart as per example
    By dip11 in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 06-27-2012, 08:42 AM
  3. Replies: 4
    Last Post: 03-20-2011, 05:52 PM
  4. automate chart and format data point colors
    By Grateful in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 02-16-2009, 11:28 AM
  5. Chart to only reflect points where data present?
    By mhb22079 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 12-04-2007, 01:12 PM

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