+ Reply to Thread
Results 1 to 3 of 3

Test for presence of chart on active sheet

  1. #1
    Katherine
    Guest

    Test for presence of chart on active sheet

    I've written the following code to create a chart on the active sheet.


    'Select the range of data to chart (using the value from FindLastUsedRow)
    Range(Cells(2, 1), Cells(intLastRow, 7)).Select

    'Create the chart
    With ActiveSheet.ChartObjects.Add(Left:=100, Width:=375, Top:=75,
    Height:=255).Chart
    .SetSourceData Source:=ActiveSheet.Range(Cells(2, 1), Cells(intLastRow,
    7))
    .ChartType = xlColumnClustered
    .Axes(xlValue).MajorUnit = 1
    End With


    Two questions....

    1) How can I check for the presence of a chart on the active sheet? The idea
    is that the user clicks the button to initially create and then update the
    chart, and I figured deleting and redrawing it would be the way to do this. I
    need to be able to check if the chart on that sheet has already been created
    and, if so, delete it.

    2) Can someone explain to me the units of measurement that decide
    whereabouts in the sheet the chart is placed? I got the (Left:=100,
    Width:=375, Top:=75, Height:=255) above from the macro recorder, which is all
    well and good but I don't understand exactly how it works.

    Any suggestions greatly appreciated

  2. #2
    AA2e72E
    Guest

    RE: Test for presence of chart on active sheet

    1. if activesheet.chartobjects.count is zero, there are no charts.
    2. the measurements are points: refer to the help file & search for 'Left
    Property'

    "Katherine" wrote:

    > I've written the following code to create a chart on the active sheet.
    >
    >
    > 'Select the range of data to chart (using the value from FindLastUsedRow)
    > Range(Cells(2, 1), Cells(intLastRow, 7)).Select
    >
    > 'Create the chart
    > With ActiveSheet.ChartObjects.Add(Left:=100, Width:=375, Top:=75,
    > Height:=255).Chart
    > .SetSourceData Source:=ActiveSheet.Range(Cells(2, 1), Cells(intLastRow,
    > 7))
    > .ChartType = xlColumnClustered
    > .Axes(xlValue).MajorUnit = 1
    > End With
    >
    >
    > Two questions....
    >
    > 1) How can I check for the presence of a chart on the active sheet? The idea
    > is that the user clicks the button to initially create and then update the
    > chart, and I figured deleting and redrawing it would be the way to do this. I
    > need to be able to check if the chart on that sheet has already been created
    > and, if so, delete it.
    >
    > 2) Can someone explain to me the units of measurement that decide
    > whereabouts in the sheet the chart is placed? I got the (Left:=100,
    > Width:=375, Top:=75, Height:=255) above from the macro recorder, which is all
    > well and good but I don't understand exactly how it works.
    >
    > Any suggestions greatly appreciated


  3. #3
    Katherine
    Guest

    RE: Test for presence of chart on active sheet



    "AA2e72E" wrote:

    > 1. if activesheet.chartobjects.count is zero, there are no charts.
    > 2. the measurements are points: refer to the help file & search for 'Left
    > Property'


    Thanks, the activesheet.chartobjects.count is just what I needed.

    As for 2) I'd already tried searching the help files (both excel help and
    the vbe help) but hadn't come across any useful results. Nevermind, I'll keep
    googling it.

+ Reply to Thread

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