Insert Graphs based on multiple unknown size sets of data?

spwath

New Member
Joined
Aug 13, 2019
Messages
1
I have a tool that creates a csv file with multiple tables of data. These tables are seperated by a blank line of cells. I want to be able to copy this data, and paste it into an excel sheet, and have the sheet auto generate a line graph for each table of data. Is there a way to do this?
Example of data that would be pasted (there would be a known number of tables, but unknown size of each):
This example has two tables that I have circled

 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,207
Office Version
2007
Platform
Windows
Try this

Code:
Sub [COLOR=#0000ff]Insert_Graphs[/COLOR]()
  Dim bl As Range
  For Each bl In Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
    bl.EntireRow.Copy
    Sheets.Add after:=Sheets(Sheets.Count)
    ActiveSheet.Paste
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.SetSourceData Source:=Range("$A$1:$E$" & Range("A" & Rows.Count).End(xlUp).Row)
    ActiveChart.ChartType = xlLineStacked
  Next
End Sub
HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (Insert_Graphs) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,630
Messages
5,488,004
Members
407,617
Latest member
Samanthad2007

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top