0

So I figured out how to select the bottom three rows of the spreadsheet:

Range("A" & Cells.Rows.Count).End(xlUp).Select
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(-2, 6)).Select

However, I can't figure out how to relate my selection to the data range selected in my recorded macro:

ActiveChart.SetSourceData Source:=Range("Sheet1!$A$26:$G$28")

Any suggestions you have would be much appreciated.

Byron Wall
  • 3,970
  • 2
  • 13
  • 29

1 Answers1

0

You have to fully qualify your Ranges. This issue shows up once and again (e.g., this).

What does this mean? Do not use Cells, Range, Rows or Columns without specifying which Worksheet they belong to, unless you specifically want to do that (and even in that case, explicitly using ActiveSheet improves readability and reduces the chances of errors, similar to using Option Explicit). For instance, replace

ActiveChart.SetSourceData Source:=Range("Sheet1!$A$26:$G$28")

with

Dim wsdata as Worksheet
Set wsdata = ActiveWorkbook.Sheets("Sheet1")
ActiveChart.SetSourceData Source:=wsdata.Range("$A$26:$G$28")

*Note *: You can work with the ActiveCell only when the Worksheet that it is on is the ActiveSheet [MSDN].

Community
  • 1
  • 1