PDA

View Full Version : Make seperate columns range formula refer to cell in vba?



JKB
10-12-2015, 12:54 AM
Hi!

I have this code:

'ActiveChart.SetSourceData Source:=shtHis.Range("A1:A1238,D1:D1238")

I would like the "1238" not to refer to a cell instead, is this possible? it's important that the two columns are "seperate" i.e. that column a, b, c and d aren't selected but only column a and d?
The cell value could fx be "100" and then the graph data would only display the shtHis.Range("A1:A100,D1:D100")

Can anybody help me with this?

Cheers

Aflatoon
10-12-2015, 01:49 AM
Something like this:

Dim lRow as Long
lRow = sheets("some sheet").Range("A1").value
ActiveChart.SetSourceData Source:=shtHis.Range("A1:A" & lRow & ",D1:D" & lRow)

JKB
10-12-2015, 01:57 AM
Worked!!! Thank you Aflatoon!

Aflatoon
10-12-2015, 02:12 AM
You're welcome.