+ Reply to Thread
Results 1 to 2 of 2

Generating graphs automatically

Hybrid View

  1. #1
    Registered User
    Join Date
    04-28-2007
    Posts
    3

    Generating graphs automatically

    Hello,

    I need excel to generate graphs automatically when transfering data from a certain folder.

    - I have data that is in .DDF which I conver to .asc which I have wrote a Macro to convert that into excel. After doing that I get 4 column s of data:

    1. Time it takes to perform a test --> Column A
    2. The force (in Newtons) --> Column B
    3. The Angle (degree) --> Column C
    4. The angular velocity --> Column D

    I get these columns of data per each file I have which it automatically excel puts them in different sheets for me, however, I wanted to know if excel can generate graphs by taking data from certain columns and generate graphs automatically.

    The data that comes in is either velocity (V...) or Force (HL...), which the files name it self starts with V... or HL.... However, to generate the graph for V... you need to get Column C as x-axis and Column D as y-axis.
    To get HL... graph you need to graph Column C as x-axis and Column B as y-axis.

    There is different number of Rows per file, however, the columns are all the same for all of them.


    Attached is an excel sheet with data and graphs which I generated Manualy.


    Thanks a lot for all your help.


    Irfan
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481
    Here's a littel code to get you started. If you have your import macro call this GenerateGraphs after the data is imported this should make a single graph with x-axis data from column C and y-axis data from columns B and D.

    Try recording a macro while manipulating the graph properties to see what commands are used for changing each.

    HTH

    Sub GenerateGraphs()
    Dim numRows As Double, FirstRow As Integer
    FirstRow = 1 'Change this to the row where your data starts
    numRows = ActiveSheet.Cells(Rows.Count, "C").End(xlUp).Row
    
        Charts.Add
        ActiveChart.ChartType = xlXYScatter
        ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("B" & FirstRow & ":D" & numRows), PlotBy _
            :=xlColumns
        ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R" & FirstRow & "C3:R" & numRows & "C3"
        ActiveChart.SeriesCollection(1).Values = "=Sheet1!R" & FirstRow & "C4:R" & numRows & "C4"
        ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R" & FirstRow & "C3:R" & numRows & "C3"
        ActiveChart.SeriesCollection(2).Values = "=Sheet1!R" & FirstRow & "C2:R" & numRows & "C2"
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
        With ActiveChart
            .HasTitle = False
            .Axes(xlCategory, xlPrimary).HasTitle = False
            .Axes(xlValue, xlPrimary).HasTitle = False
        End With
    End Sub

+ 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