title: Excel Visual Basic Macro- Selecting data dynamically for a chart?
body: <p>So, this question is probably fairly stupid, but I'm not too familiar with Excel VBA. Here's my generated Macro code which imports data from a text file and graphs it.</p>
  
  <pre><code>Sub getData()
  '
  ' getData Macro
  '
  
  '
  With ActiveSheet.QueryTables.Add(Connection:= _
      "TEXT;C:\data.txt", Destination:=Range("$D$3"))
      .Name = "data_2"
      .FieldNames = True
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = True
      .RefreshOnFileOpen = False
      .RefreshStyle = xlInsertDeleteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = True
      .RefreshPeriod = 0
      .TextFilePromptOnRefresh = False
      .TextFilePlatform = 437
      .TextFileStartRow = 1
      .TextFileParseType = xlDelimited
      .TextFileTextQualifier = xlTextQualifierDoubleQuote
      .TextFileConsecutiveDelimiter = False
      .TextFileTabDelimiter = False
      .TextFileSemicolonDelimiter = False
      .TextFileCommaDelimiter = True
      .TextFileSpaceDelimiter = False
      .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1)
      .TextFileTrailingMinusNumbers = True
      .Refresh BackgroundQuery:=False
  End With
  Range("D3:H4").Select
  ActiveSheet.Shapes.AddChart.Select
  ActiveChart.ChartType = xlXYScatter
  ActiveChart.SetSourceData Source:=Range("Sheet1!$D$3:$H$4")
  End Sub
  </code></pre>
  
  <p>Essentially, because the data inputted from data.txt can be any length, this program does not work; it just goes from D3:H3. I'd like the chart to use the data from D3 to HX, where X is the end of the data row. How would I do this?
  Thanks for helping an <s>idiot</s>!</p>