Excel/VBA question: Link ChartTitle at run-time, anyone?

  • Thread starter Thread starter Knut Hollund
  • Start date Start date
K

Knut Hollund

Using VBA and Excel I'm trying to link the ChartTitle of an embedded chart
to a cell, but I always get an runtime error. Do anyone know how to do this?

Here is what I try to do:

.ChartObjects(name).Chart.ChartTitle.Text = "=" & .Cells(row, 1).address

(the . is a worksheet, name is the correct string and row is an nice
integer..)

K__t
 
Hi,

Try this,

..ChartObjects(1).Chart.ChartTitle.Text = _
"=" & ActiveCell.Parent.Name & "!" _
& ActiveCell.Address(ReferenceStyle:=xlR1C1)


Knut said:
Using VBA and Excel I'm trying to link the ChartTitle of an embedded chart
to a cell, but I always get an runtime error. Do anyone know how to do this?

Here is what I try to do:

.ChartObjects(name).Chart.ChartTitle.Text = "=" & .Cells(row, 1).address

(the . is a worksheet, name is the correct string and row is an nice
integer..)

K__t

--

Cheers
Andy

http://www.andypope.info
 
Andy Pope said:
Hi,

Try this,

.ChartObjects(1).Chart.ChartTitle.Text = _
"=" & ActiveCell.Parent.Name & "!" _
& ActiveCell.Address(ReferenceStyle:=xlR1C1)

Thanks, for the answer, I didn't think about the reference style. The
answer didn't solve my problem completely, but it made me test something I
had tested before (External) and then suddenly I recognized that the title
was blank.., ohh not again... As always when a bug is difficult to find, its
a trivial error! Sorry to bother you all. Here is the code that solved my
problem:

..ChartObjects(name).Chart.ChartTitle.Text = .Cells(row + 1,
1).address(External:=True, ReferenceStyle:=xlR1C1)

(note the row+1 (grrr), and bytheway no need to activate anything)

K__t
 
Back
Top