+ Reply to Thread
Results 1 to 3 of 3

updating data location to build a VBA graph

  1. #1
    alvis@mail.act.edu
    Guest

    updating data location to build a VBA graph

    hello,

    I am trying to build this simple macro where i can hit a keystroke and
    graph whatever cells i have selected. The problem is that the macro
    only graphs only from a fixed range and i want to be able to graph any
    data i select.

    here is the macro:

    Sub graph()
    '
    ' graph Macro
    '
    '
    ' Keyboard Shortcut: Ctrl+Shift+G
    '
    Charts.Add
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),
    PlotBy:= _
    xlRows
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    With ActiveChart
    .HasTitle = False
    .Axes(xlCategory, xlPrimary).HasTitle = False
    .Axes(xlValue, xlPrimary).HasTitle = False
    End With
    ActiveChart.PlotArea.Select
    With Selection.Border
    .Weight = xlThin
    .LineStyle = xlNone
    End With
    With Selection.Interior
    .ColorIndex = 15
    .PatternColorIndex = 1
    .Pattern = xlSolid
    End With
    With Selection.Border
    .Weight = xlHairline
    .LineStyle = xlNone
    End With
    Selection.Interior.ColorIndex = xlNone
    ActiveChart.ChartArea.Select
    With Selection.Border
    .Weight = 2
    .LineStyle = 0
    End With
    Selection.Interior.ColorIndex = xlAutomatic
    Sheets("Sheet1").DrawingObjects("Chart 1").RoundedCorners = False
    Sheets("Sheet1").DrawingObjects("Chart 1").Shadow = False
    ActiveChart.PlotArea.Select
    With Selection.Border
    .Weight = xlThin
    .LineStyle = xlAutomatic
    End With
    Selection.Interior.ColorIndex = xlNone
    ActiveChart.ChartArea.Select
    ActiveChart.SeriesCollection(1).Select
    With Selection.Border
    .ColorIndex = 57
    .Weight = xlThick
    .LineStyle = xlContinuous
    End With
    With Selection
    .MarkerBackgroundColorIndex = xlNone
    .MarkerForegroundColorIndex = xlNone
    .MarkerStyle = xlNone
    .Smooth = False
    .MarkerSize = 3
    .Shadow = False
    End With
    ActiveChart.ChartArea.Select
    ActiveChart.Legend.Select
    Selection.Delete
    End Sub


    so graphs only data from C5:K5 and i want to be able to graph any data
    i select...
    thanks,
    alvis


  2. #2
    Tom Ogilvy
    Guest

    RE: updating data location to build a VBA graph

    possibly change

    ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),

    to

    ActiveChart.SetSourceData Source:=Selection

    --
    Regards,
    Tom Ogilvy


    "alvis@mail.act.edu" wrote:

    > hello,
    >
    > I am trying to build this simple macro where i can hit a keystroke and
    > graph whatever cells i have selected. The problem is that the macro
    > only graphs only from a fixed range and i want to be able to graph any
    > data i select.
    >
    > here is the macro:
    >
    > Sub graph()
    > '
    > ' graph Macro
    > '
    > '
    > ' Keyboard Shortcut: Ctrl+Shift+G
    > '
    > Charts.Add
    > ActiveChart.ChartType = xlLine
    > ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),
    > PlotBy:= _
    > xlRows
    > ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    > With ActiveChart
    > .HasTitle = False
    > .Axes(xlCategory, xlPrimary).HasTitle = False
    > .Axes(xlValue, xlPrimary).HasTitle = False
    > End With
    > ActiveChart.PlotArea.Select
    > With Selection.Border
    > .Weight = xlThin
    > .LineStyle = xlNone
    > End With
    > With Selection.Interior
    > .ColorIndex = 15
    > .PatternColorIndex = 1
    > .Pattern = xlSolid
    > End With
    > With Selection.Border
    > .Weight = xlHairline
    > .LineStyle = xlNone
    > End With
    > Selection.Interior.ColorIndex = xlNone
    > ActiveChart.ChartArea.Select
    > With Selection.Border
    > .Weight = 2
    > .LineStyle = 0
    > End With
    > Selection.Interior.ColorIndex = xlAutomatic
    > Sheets("Sheet1").DrawingObjects("Chart 1").RoundedCorners = False
    > Sheets("Sheet1").DrawingObjects("Chart 1").Shadow = False
    > ActiveChart.PlotArea.Select
    > With Selection.Border
    > .Weight = xlThin
    > .LineStyle = xlAutomatic
    > End With
    > Selection.Interior.ColorIndex = xlNone
    > ActiveChart.ChartArea.Select
    > ActiveChart.SeriesCollection(1).Select
    > With Selection.Border
    > .ColorIndex = 57
    > .Weight = xlThick
    > .LineStyle = xlContinuous
    > End With
    > With Selection
    > .MarkerBackgroundColorIndex = xlNone
    > .MarkerForegroundColorIndex = xlNone
    > .MarkerStyle = xlNone
    > .Smooth = False
    > .MarkerSize = 3
    > .Shadow = False
    > End With
    > ActiveChart.ChartArea.Select
    > ActiveChart.Legend.Select
    > Selection.Delete
    > End Sub
    >
    >
    > so graphs only data from C5:K5 and i want to be able to graph any data
    > i select...
    > thanks,
    > alvis
    >
    >


  3. #3
    alvis@mail.act.edu
    Guest

    Re: updating data location to build a VBA graph

    i tried that but doesn't work,
    thanks though
    Tom Ogilvy wrote:
    > possibly change
    >
    > ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),
    >
    > to
    >
    > ActiveChart.SetSourceData Source:=Selection
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "alvis@mail.act.edu" wrote:
    >
    > > hello,
    > >
    > > I am trying to build this simple macro where i can hit a keystroke and
    > > graph whatever cells i have selected. The problem is that the macro
    > > only graphs only from a fixed range and i want to be able to graph any
    > > data i select.
    > >
    > > here is the macro:
    > >
    > > Sub graph()
    > > '
    > > ' graph Macro
    > > '
    > > '
    > > ' Keyboard Shortcut: Ctrl+Shift+G
    > > '
    > > Charts.Add
    > > ActiveChart.ChartType = xlLine
    > > ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C5:K5"),
    > > PlotBy:= _
    > > xlRows
    > > ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
    > > With ActiveChart
    > > .HasTitle = False
    > > .Axes(xlCategory, xlPrimary).HasTitle = False
    > > .Axes(xlValue, xlPrimary).HasTitle = False
    > > End With
    > > ActiveChart.PlotArea.Select
    > > With Selection.Border
    > > .Weight = xlThin
    > > .LineStyle = xlNone
    > > End With
    > > With Selection.Interior
    > > .ColorIndex = 15
    > > .PatternColorIndex = 1
    > > .Pattern = xlSolid
    > > End With
    > > With Selection.Border
    > > .Weight = xlHairline
    > > .LineStyle = xlNone
    > > End With
    > > Selection.Interior.ColorIndex = xlNone
    > > ActiveChart.ChartArea.Select
    > > With Selection.Border
    > > .Weight = 2
    > > .LineStyle = 0
    > > End With
    > > Selection.Interior.ColorIndex = xlAutomatic
    > > Sheets("Sheet1").DrawingObjects("Chart 1").RoundedCorners = False
    > > Sheets("Sheet1").DrawingObjects("Chart 1").Shadow = False
    > > ActiveChart.PlotArea.Select
    > > With Selection.Border
    > > .Weight = xlThin
    > > .LineStyle = xlAutomatic
    > > End With
    > > Selection.Interior.ColorIndex = xlNone
    > > ActiveChart.ChartArea.Select
    > > ActiveChart.SeriesCollection(1).Select
    > > With Selection.Border
    > > .ColorIndex = 57
    > > .Weight = xlThick
    > > .LineStyle = xlContinuous
    > > End With
    > > With Selection
    > > .MarkerBackgroundColorIndex = xlNone
    > > .MarkerForegroundColorIndex = xlNone
    > > .MarkerStyle = xlNone
    > > .Smooth = False
    > > .MarkerSize = 3
    > > .Shadow = False
    > > End With
    > > ActiveChart.ChartArea.Select
    > > ActiveChart.Legend.Select
    > > Selection.Delete
    > > End Sub
    > >
    > >
    > > so graphs only data from C5:K5 and i want to be able to graph any data
    > > i select...
    > > thanks,
    > > alvis
    > >
    > >



+ 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