Automated charting VB code problem

D

Danimal

Hi,

I am trying to write code to automatically create a series of chart
using difference data when the macro is run. I am having a proble
defining the chart ranges in the macro...

This code works, using a static range:
rng2 = "I2:I42"
ActiveChart.SetSourceData Source:=Sheets("All").Range(rng2), _
PlotBy:=xlColumns

But when I try to build the range string using the code below, I get
runtime error 1004:
T1 = 2
T2 = 42
rng3 = "I" + Str(T1) + ":" + "I" + Str(T2)
ActiveChart.SetSourceData Source:=Sheets("All").Range(rng3), _
PlotBy:=xlColumns

Looking at the differences of rng2 and rng3, the watch shows th
following:
rng2 "I2:I42" Type: Variant/String
rng3 "I 2:I 42" Type: Variant/String

I think the spaces in rng3 between the I's and the numbers are causin
the problem, how do I get rid of these spaces??? Any other ideas o
defining the range? I tried to use Range(Cells(T1,9),Cells(T2,9)), bu
it did not work either...

Thanks in advance,
Da
 
D

Don Lloyd

Hi Dan,

Try the folowing
rng3 = "I" + Str(T1) + ":" + "I" + Str(T2)
change to
rng3 = "I" & T1 & ":" & "I" & T2

The Str function provides a leading space for the +- sign.

regards,
Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top