Solved

Automatically create graph in excel when importing data

Posted on 2012-04-08
4
202 Views
Last Modified: 2013-07-23
I have created the attached spreasheet (DR Marker Feed New.xlsm) which imports 3 sets of stock market data from Yahoo finance. For each set of data I would like to automatically generate a line graph in a separate worksheet. The data range will expand on a daily basis so the graph's range needs to dynamically expand to accomodate this. Each graph needs to also include a horizontal line depicting -40% below the most recent market closing price.
0
Comment
Question by:draeside
4 Comments
 

Author Comment

by:draeside
ID: 37822391
file attached
DR-Market-Feed-new.xlsm
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 37827310
can you post an update with example of the chart you want?
i guessed it is the AdjClose that you want graphed ?

Is it ok to delete the charts prior to loading new ones ?

try this code and advise changes necessary. It only creates the first chart but others are easier then.

Sub Trial1()

    Sheets("All 3 Indexes").Activate
    
    'insert new column 60%
    Columns("J:J").Select
    Selection.Delete
    Range("J6").Activate
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("J7").Select
    ActiveCell.FormulaR1C1 = "40%close"
    
    'calc 60% of last close
    Range("J8").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]*60%"
    
    'copy it down
    Range("J8").Select
    Selection.Copy
    Range("I8").Select

    Selection.End(xlDown).Select
    Selection.Offset(0, 1).Select
    Range(Selection, Selection.End(xlUp)).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Selection.End(xlUp).Select
    Range("H7").Select
    
    Dim cht As Chart
    
    Sheets("Charts").Shapes.AddChart(Left:=50, Top:=50, Width:=800, Height:=1200).Select
    Sheets("Charts").Activate
    ActiveChart.SetSourceData Source:=Range("'All 3 Indexes'!$C$7:$J$6325")
    ActiveChart.ChartType = xlLine
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.SeriesCollection(1).Delete
    ActiveChart.SeriesCollection(1).Delete
    
    Set cht = ActiveChart
    cht.HasTitle = True
    cht.ChartTitle.Text = "Chart 1"
    
    Range("L7").Select
End Sub

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question