nigelandrewfoster
Well-known Member
- Joined
- May 27, 2009
- Messages
- 747
Hi, I'm new to using charts and macros together. I wrote the code below to enable the chart I am displaying only to use that block of data which is appropriate (it looks for both col A and col B being zero to define its boundaries) but the code stops at the red line, "Application defined or object defined error". I have done a fair bit of tinkering with it, but still no joy. What am I doing wrong, please? Thanks for your help.
Nigel
By the way, discovered the [a1] method of entering ranges recently. Why wasn't I told about this before? Much quicker than Range("a1"). However, what is the [] equivalent of Range("a25", r), please? Because it doesn't work if you type [[a25],r], as I would expect. Thanks.
Nigel
Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim r As Range, y As Integer
y = 0
Do
If [a1].Offset(y) = 0 And [b1].Offset(y) = 0 Then Exit Do
y = y + 1
Loop
Set r = [b24].Offset(y - 1)
Set r = Range("a25", r)
[COLOR="Red"] ChartObjects(1).Chart.SetSourceData Source:=Sheets("Graph").Range(r), _
PlotBy:=xlColumns[/COLOR]
End Sub
By the way, discovered the [a1] method of entering ranges recently. Why wasn't I told about this before? Much quicker than Range("a1"). However, what is the [] equivalent of Range("a25", r), please? Because it doesn't work if you type [[a25],r], as I would expect. Thanks.
Last edited: