Solved

Automatically create graph in excel when importing data

Posted on 2012-04-08
4
199 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
Comment Utility
file attached
DR-Market-Feed-new.xlsm
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now