Hi,

I have a macro which adds new data series from a 3 column range selection. What I would like to do is to alter the code so that it can select columns from a different ranges (for example colum A, C, F). Is there an efficent way to change this ?

Sub PopulateChartFromTable()
  Dim cht As Chart
  Dim rng As range
  Dim sPrompt As String
  Dim iSrs As Long
  Dim srs As Series
  Dim iRow As Long
  Dim iRowStart As Long
  Dim iRowEnd As Long
  Dim sSeries As String

  If ActiveChart Is Nothing Then
    MsgBox "Select a chart and try again.", vbExclamation
    GoTo ExitSub
  End If

  sPrompt = "Select a three-column range with your data."
  sPrompt = sPrompt & vbNewLine & "  Column 1: Series title"
  sPrompt = sPrompt & vbNewLine & "  Column 2: X values"
  sPrompt = sPrompt & vbNewLine & "  Column 3: Y values"
  sPrompt = sPrompt & vbNewLine & "Avoid blank cells"

  On Error Resume Next
  Set rng = Application.InputBox(Prompt:=sPrompt, Type:=8)
  On Error GoTo 0
  If rng Is Nothing Then GoTo ExitSub

  Set cht = ActiveChart
  Do
    If cht.SeriesCollection.count = 0 Then Exit Do
    cht.SeriesCollection(1).Delete
  Loop

  sSeries = ""
  iSrs = 0
  For iRow = 1 To rng.Rows.count + 1
    If rng.Cells(iRow, 1).Value <> sSeries Or iRow > rng.Rows.count Then
      If iSrs > 0 Then
        iRowEnd = iRow - 1
        Set srs = cht.SeriesCollection.NewSeries
        With srs
          .Values = rng.Cells(iRowStart, 3).Resize(iRowEnd + 1 - iRowStart)
          .XValues = rng.Cells(iRowStart, 2).Resize(iRowEnd + 1 - iRowStart)
          .Name = rng.Cells(iRowStart, 1).Value
          .ApplyDataLabels ShowSeriesName:=True, _
              ShowCategoryName:=False, showvalue:=False
        End With
      End If
      iRowStart = iRow
      sSeries = rng.Cells(iRow, 1).Value
      iSrs = iSrs + 1
    End If
  Next

ExitSub:
  Application.ScreenUpdating = True
End Sub

Regards,
Nick