title: VBA to plot dynamic range
body: <p>I have an excel 2010 macro enabled workbook.  The workbook has several sheets.  The first sheet has a macro assigned button that imports a csv file.  The csv file loads into an existing sheet named “Data”.  The imported csv file loads into columns with row 1 acting as a header for the data below.  For example, A1 is named “Time” and cell A2 down is the time data.  Cell B1 is named “Temperature” and cell B2 down is the temperature data related to each time reading.  The workbook has a third existing sheet in the workbook named “Temperature Plot”.  I would like to automatically chart Temperature versus Time on this sheet by referencing the values from the “Data” sheet.  (Time is x-axis and Temp is y-axis)</p>
  
  <p>The problem is that the imported csv file that loads into the “Data” sheet will have a different number of rows each time.  Sometimes the imported csv file may have 25 rows of data and other times 100,000 rows of data.  Lets say I import a csv with 1000 rows of data, the workbook also plots the blank cells since my chart is pre-set to capture the entire column.  As a result, the chart data is squeezed to the left.  If I pre-set the number of rows to be plotted to 1000 then the next imported csv file with more than 1000 rows will not plot beyond 1000 rows.</p>
  
  <p>I've tried rendering cell with #NA formula to avoid plotting empty cells but this solution creates a massive file.</p>
  
  <p>Is there a way to create a macro that generates a line graph of the data:</p>
  
  <p>y-axis = (B2 to the last B cell with a number)
  versus
  x-axis = (A2 to the last A cell with a number)</p>
  
  <p>So that each time the workbook is opened and a new csv file (regardless of how many rows) is imported the graph plots the cells with numbers and does not plot blank cells?</p>
  
  <p>Any assistance would be greatly appreciated. Thank you in advance!</p>