+ Reply to Thread
Results 1 to 8 of 8

Extract, Sort and Graph Table

Hybrid View

  1. #1
    Registered User
    Join Date
    06-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel
    Posts
    39

    Extract, Sort and Graph Table

    Hi,

    Given a long table with various columns, how can I extract the rows based on defined column data, paste the selected into another worksheet, then sort and graph it as a scatterplot?

    For Eg. with the attached spreadsheet with a list of fruits, how can the fruits that are green (watermelon and pear) be extracted, then sorted by price, and then graphed as a scatterplot (size vs price)?

    Thanks in advance!
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-14-2004
    Location
    Jämtland, Sweden
    Posts
    16

    Re: Extract, Sort and Graph Table

    I guess you could make a pivot table/graph as attached.
    Attached Files Attached Files

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,897

    Re: Extract, Sort and Graph Table

    As you do not need sorted data for scatterplot (especially when plotted with no inteconnecting lines):
    Just plot of the filtered data would do. Remember to set in properties to not change size and not move with cells.
    Attached Files Attached Files
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    06-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel
    Posts
    39

    Re: Extract, Sort and Graph Table

    Thanks for the suggestions guys!

    Is there a way to automate this using VBA code? Such that with a table of data, how can Excel automatically filter and output such scatterplots based on pre-defined criteria?

    The data in the table will be refreshed periodically.

    Thanks!

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,897

    Re: Extract, Sort and Graph Table

    have a look on such sample macro:
    Sub test()
    Dim i&, allvals, myvalcol As New Collection
    Application.ScreenUpdating = False
    ActiveSheet.AutoFilterMode = False
    allvals = Range("B3:B" & Cells(Rows.Count, "B").End(xlUp).Row).Value
    On Error Resume Next
      For i = 1 To UBound(allvals)
        myvalcol.Add allvals(i, 1), allvals(i, 1)
      Next i
    On Error GoTo 0
    For i = 1 To myvalcol.Count
      ActiveSheet.Range("A2").CurrentRegion.AutoFilter Field:=2, Criteria1:=myvalcol(i)
      ActiveSheet.ChartObjects(1).Activate
      ActiveChart.ChartTitle.Text = myvalcol(i)
      ActiveChart.ChartArea.Copy
      Cells(2, 6 + 8 * i).Select
      ActiveSheet.PasteSpecial Format:="Picture (Enhanced Metafile)", Link:= _
         False, DisplayAsIcon:=False
    Next i
    ActiveSheet.ChartObjects(1).Activate
    ActiveChart.ChartTitle.Text = "All"
    ActiveSheet.AutoFilterMode = False
    Range("A3").Select
    End Sub
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel
    Posts
    39

    Re: Extract, Sort and Graph Table

    Hi again Kaper, that's a wonderful piece of code. I've tried to use it but it gives a "application-defined or object-defined error". This occurs at the line "ActiveSheet.ChartObjects(1).Activate"

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,897

    Re: Extract, Sort and Graph Table

    Try 3 measures:
    - add
    Application.CutCopyMode = False
    before
    ActiveChart.ChartArea.Copy
    - move your main chart slightly up to have upper left corner above the row with filter header.
    - make sure all old pictures are deleted from the sheet before you start to create new. you may add such code to do so:
    Dim myshp As Shape
    For Each myshp In ActiveSheet.Shapes
      If myshp.Type = msoPicture Then myshp.Delete
    Next myshp

  8. #8
    Registered User
    Join Date
    06-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel
    Posts
    39

    Re: Extract, Sort and Graph Table

    Hi Kaper realise that a chart needs to be already created in order for this to work. It works now after I've added a chart.

    It looks nice but unfortunately the data points aren't viewable as they are pasted as images. Is there a suggestion on how to create individual tables and their own charts?

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extract formula from scatter graph
    By RunwayRiga in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-30-2014, 09:34 AM
  2. Extract and sort data from table
    By spangpang in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-19-2012, 08:08 AM
  3. Replies: 2
    Last Post: 08-29-2011, 12:29 PM
  4. VBA code to extract graph from a table
    By baroda11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-21-2008, 11:55 AM
  5. [SOLVED] How do I extract data from graph (i.e. interpolaton)
    By TauBrewer in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-24-2005, 06:35 PM

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