+ Reply to Thread
Results 1 to 8 of 8

Creating a chart from an external CSV file

Hybrid View

  1. #1
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    Try

    Set ws = ThisWorkbook.ActiveSheet
    Martin

  2. #2
    Registered User
    Join Date
    03-19-2008
    Posts
    7
    Thanks again

    I tried that and got this error:
    http://img521.imageshack.us/my.php?image=errorlc6.jpg

    This should be so simple but I can't seem to get it. There must be something terribly obvious that I'm overlooking. I've uploaded the file, if you want to have a look:
    http://www.geocities.com/mtwstorage/energyBooks.zip

    Any ideas where I'm going wrong?

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967
    The following code gets you as a graph although it might not be quite the graph that you are expecting. Adjust the Open line to the appropriate path.

    Private Sub Workbook_Open()
    Dim ws As Worksheet
        Set ws = ThisWorkbook.ActiveSheet
        Workbooks.Open "c:\energyOutput.csv"
        
        Dim n
        ThisWorkbook.Activate
        For i = ActiveSheet.ChartObjects.Count To 1 Step -1
            ActiveSheet.ChartObjects(i).Delete
        Next i
        
        ActiveSheet.Shapes.AddChart.Select
        ActiveChart.SetSourceData Source:=Workbooks("energyOutput.csv").Sheets("energyOutput").Range("$A1:$C" & Workbooks("energyOutput.csv").Sheets("energyOutput").Cells(65536, 1).End(xlUp).Row)
        ActiveChart.ChartType = xlLine
    End Sub

  4. #4
    Registered User
    Join Date
    03-19-2008
    Posts
    7
    Martin, that's absolutely perfect. Thank you so much. Sending lots of virtual kisses your way xxxxxxxxxxxxx :D

+ 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