Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Automatically create graph in excel when importing data

Posted on 2012-04-08
4
Medium Priority
?
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

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

Accepted Solution

by:
Robberbaron (robr) earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

715 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