+ Reply to Thread
Results 1 to 3 of 3

Macro to create a new chart

  1. #1
    kimbobo
    Guest

    Macro to create a new chart

    I've been using this code for a while to easily create a new chart.
    However just recently has stopped working. It now created a "default"
    excel chart as a new tab in the workbook. Any suggestions?

    '********************************************************************
    'Creates 2 data series horizontal bar chart
    '********************************************************************

    Dim myShtName As String
    myShtName = ActiveSheet.Name
    Charts.Add
    ActiveChart.ChartType = xlBarClustered 'Creates Stacked bar
    ActiveChart.SetSourceData Source:=Rng, PlotBy:=xlColumns
    'References sheet and and cell range of data to generate chart
    ActiveChart.Location Where:=xlLocationAsObject, Name:=myShtName
    With ActiveChart.Axes(xlCategory)
    .HasMajorGridlines = False
    .HasMinorGridlines = False
    End With
    With ActiveChart.Axes(xlValue)
    .HasMajorGridlines = False
    .HasMinorGridlines = False
    End With
    ActiveChart.HasLegend = True

    '********************************************************************
    'Specifies placement and height & width dimensions of chart
    '********************************************************************

    With ActiveChart.Parent
    .Top = ActiveSheet.Range("F22:Q22").Top
    .Left = ActiveSheet.Range("F22:Q52").Left
    .Height = ActiveSheet.Range("F22:Q52").Height
    .Width = ActiveSheet.Range("F22:Q22").Width
    End With


  2. #2
    NickHK
    Guest

    Re: Macro to create a new chart

    You code works fine for me.
    Is the destination (activesheet) sheet protected ?

    NickHK

    "kimbobo" <kimbobo@gmail.com> wrote in message
    news:1155677795.809976.97340@p79g2000cwp.googlegroups.com...
    > I've been using this code for a while to easily create a new chart.
    > However just recently has stopped working. It now created a "default"
    > excel chart as a new tab in the workbook. Any suggestions?
    >
    > '********************************************************************
    > 'Creates 2 data series horizontal bar chart
    > '********************************************************************
    >
    > Dim myShtName As String
    > myShtName = ActiveSheet.Name
    > Charts.Add
    > ActiveChart.ChartType = xlBarClustered 'Creates Stacked bar
    > ActiveChart.SetSourceData Source:=Rng, PlotBy:=xlColumns
    > 'References sheet and and cell range of data to generate chart
    > ActiveChart.Location Where:=xlLocationAsObject, Name:=myShtName
    > With ActiveChart.Axes(xlCategory)
    > .HasMajorGridlines = False
    > .HasMinorGridlines = False
    > End With
    > With ActiveChart.Axes(xlValue)
    > .HasMajorGridlines = False
    > .HasMinorGridlines = False
    > End With
    > ActiveChart.HasLegend = True
    >
    > '********************************************************************
    > 'Specifies placement and height & width dimensions of chart
    > '********************************************************************
    >
    > With ActiveChart.Parent
    > .Top = ActiveSheet.Range("F22:Q22").Top
    > .Left = ActiveSheet.Range("F22:Q52").Left
    > .Height = ActiveSheet.Range("F22:Q52").Height
    > .Width = ActiveSheet.Range("F22:Q22").Width
    > End With
    >




  3. #3
    kimbobo
    Guest

    Re: Macro to create a new chart

    Hi Nick,

    Yeah, the code worked fine about 2 minutes before I used it again. Then
    It just suddenly stopped. When I open up the debugger it points to
    this:

    ActiveChart.Location Where:=xlLocationAsObject, Name:=myShtName

    Both the sheet and the workbook are unprotected.

    Any other ideas? =)

    Thanks,

    Kim

    NickHK wrote:
    > You code works fine for me.
    > Is the destination (activesheet) sheet protected ?
    >
    > NickHK
    >
    > "kimbobo" <kimbobo@gmail.com> wrote in message
    > news:1155677795.809976.97340@p79g2000cwp.googlegroups.com...
    > > I've been using this code for a while to easily create a new chart.
    > > However just recently has stopped working. It now created a "default"
    > > excel chart as a new tab in the workbook. Any suggestions?
    > >
    > > '********************************************************************
    > > 'Creates 2 data series horizontal bar chart
    > > '********************************************************************
    > >
    > > Dim myShtName As String
    > > myShtName = ActiveSheet.Name
    > > Charts.Add
    > > ActiveChart.ChartType = xlBarClustered 'Creates Stacked bar
    > > ActiveChart.SetSourceData Source:=Rng, PlotBy:=xlColumns
    > > 'References sheet and and cell range of data to generate chart
    > > ActiveChart.Location Where:=xlLocationAsObject, Name:=myShtName
    > > With ActiveChart.Axes(xlCategory)
    > > .HasMajorGridlines = False
    > > .HasMinorGridlines = False
    > > End With
    > > With ActiveChart.Axes(xlValue)
    > > .HasMajorGridlines = False
    > > .HasMinorGridlines = False
    > > End With
    > > ActiveChart.HasLegend = True
    > >
    > > '********************************************************************
    > > 'Specifies placement and height & width dimensions of chart
    > > '********************************************************************
    > >
    > > With ActiveChart.Parent
    > > .Top = ActiveSheet.Range("F22:Q22").Top
    > > .Left = ActiveSheet.Range("F22:Q52").Left
    > > .Height = ActiveSheet.Range("F22:Q52").Height
    > > .Width = ActiveSheet.Range("F22:Q22").Width
    > > End With
    > >



+ 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