+ Reply to Thread
Results 1 to 9 of 9

Macro for Graphing Current Sheet?

  1. #1
    Registered User
    Join Date
    06-30-2005
    Posts
    61

    Macro for Graphing Current Sheet?

    I would like to have my macro graph the sheet I am on without having to type in different names as I change different files. The SourceData looks like this right now:

    ActiveChart.SetSourceData Source:=Sheets("sName").Range("A1:B400"), PlotBy _
    :=xlColumns

    Is there any way I can get sName to be the name of the current worksheet I am viewing?

  2. #2
    Registered User
    Join Date
    06-30-2005
    Posts
    61
    Can anyone help?

  3. #3
    Tim Williams
    Guest

    Re: Macro for Graphing Current Sheet?

    ActiveChart.SetSourceData Source:=ActiveSheet.Range("A1:B400"), PlotBy
    :=xlColumns

    Tim


    "Losse" <Losse.1rggwe_1120162141.7334@excelforum-nospam.com> wrote in
    message news:Losse.1rggwe_1120162141.7334@excelforum-nospam.com...
    >
    > I would like to have my macro graph the sheet I am on without having
    > to
    > type in different names as I change different files. The SourceData
    > looks like this right now:
    >
    > ActiveChart.SetSourceData Source:=Sheets("sName").Range("A1:B400"),
    > PlotBy _
    > :=xlColumns
    >
    > Is there any way I can get sName to be the name of the current
    > worksheet I am viewing?
    >
    >
    > --
    > Losse
    > ------------------------------------------------------------------------
    > Losse's Profile:
    > http://www.excelforum.com/member.php...o&userid=24813
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=383681
    >




  4. #4
    Registered User
    Join Date
    06-30-2005
    Posts
    61
    That only gives me an error. It tells me "Object doesn't support this property or method." I belive there needs to be an "_" after the PlotBy as well.

  5. #5
    Registered User
    Join Date
    06-30-2005
    Posts
    61
    Is what I'm asking impossible?

  6. #6
    Tim Williams
    Guest

    Re: Macro for Graphing Current Sheet?

    Did the line you posted actually work? I was assuming it did....

    You could always try

    dim sName as string

    sName = activesheet.name

    ActiveChart.SetSourceData _
    Source:=Sheets(sName).Range("A1:B400"), _
    PlotBy :=xlColumns

    Tim

    "Losse" <Losse.1rhs2n_1120223253.5446@excelforum-nospam.com> wrote in
    message news:Losse.1rhs2n_1120223253.5446@excelforum-nospam.com...
    >
    > That only gives me an error. It tells me "Object doesn't support
    > this
    > property or method." I belive there needs to be an "_" after the
    > PlotBy
    > as well.
    >
    >
    > --
    > Losse
    > ------------------------------------------------------------------------
    > Losse's Profile:
    > http://www.excelforum.com/member.php...o&userid=24813
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=383681
    >




  7. #7
    Jon Peltier
    Guest

    Re: Macro for Graphing Current Sheet?

    Obviously the newsreader inserted a line feed between "PlotBy" and ":=".
    Does the code work when it's all on a single line? If your first posted
    code worked, so should Tim's altered code.

    - Jon
    -------
    Jon Peltier, Microsoft Excel MVP
    Peltier Technical Services
    Tutorials and Custom Solutions
    http://PeltierTech.com/
    _______


    Losse wrote:

    > That only gives me an error. It tells me "Object doesn't support this
    > property or method." I belive there needs to be an "_" after the PlotBy
    > as well.
    >
    >


  8. #8
    carloshernandezy@gmail.com
    Guest

    Re: Macro for Graphing Current Sheet?

    Today i have solved the same problem you have this code is in one
    Workbook and creates a chart in the active workbook the values are in
    column "C".

    Sub Grafico()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim cht As Excel.Chart


    Set wb = ActiveWorkbook
    '

    Set ws = wb.Sheets(1)

    'nombra la hoja actual
    ws.Name = "TOC"

    'Define el rango de trabajo RngC
    wb.Names.Add Name:="RngC", RefersToR1C1:= _
    "=OFFSET(TOC!R1C3,0,0,COUNTA(TOC!C3))"

    Application.ScreenUpdating = False
    Set cht = ws.ChartObjects.Add(50, 50, 400, 300).Chart



    With cht
    .ChartType = xlXYScatterSmoothNoMarkers



    ..SetSourceData Source:=ws.Range("TOC!RngC"), PlotBy:=xlColumns
    .Location Where:=xlLocationAsObject, Name:="TOC"
    .HasTitle = True
    .ChartTitle.Characters.Text = "TOC en "
    With .Axes(xlCategory)
    .HasMajorGridlines = False
    .HasMinorGridlines = False
    End With
    With .Axes(xlValue)
    .HasTitle = True
    .AxisTitle.Characters.Text = "ppb"
    .HasMajorGridlines = False
    .HasMinorGridlines = False
    End With
    .HasLegend = False
    With .PlotArea
    With .Border
    .ColorIndex = 16
    .Weight = xlThin
    .LineStyle = xlContinuous
    End With
    With .Interior
    .ColorIndex = 2
    .PatternColorIndex = 1
    .Pattern = xlSolid
    End With
    End With
    End With
    Application.ScreenUpdating = True


    'Quita las unidades del eje X
    ActiveChart.Axes(xlCategory).Select
    ActiveChart.ChartArea.Select
    With ActiveChart
    .HasAxis(xlCategory, xlPrimary) = False
    .HasAxis(xlValue, xlPrimary) = True
    End With
    ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
    End Sub

    Jon Peltier wrote:
    > Obviously the newsreader inserted a line feed between "PlotBy" and ":=".
    > Does the code work when it's all on a single line? If your first posted
    > code worked, so should Tim's altered code.
    >
    > - Jon
    > -------
    > Jon Peltier, Microsoft Excel MVP
    > Peltier Technical Services
    > Tutorials and Custom Solutions
    > http://PeltierTech.com/
    > _______
    >
    >
    > Losse wrote:
    >
    > > That only gives me an error. It tells me "Object doesn't support this
    > > property or method." I belive there needs to be an "_" after the PlotBy
    > > as well.
    > >
    > >



  9. #9
    Registered User
    Join Date
    06-30-2005
    Posts
    61
    Thank you, Tim. That worked perfectly for me. It did not work, however, until I changed it into the format you posted.

+ 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