multiple charts - same worksheet - non contiguous cells - VBA code

9davros8

New Member
Joined
Jul 11, 2017
Messages
23
hi

problem - I have found some code on the net that basically does what I want. I run the code and it loops through my data on sheet1 and outputs charts on sheet2. however the code gets the source data only from each row and does not allow for non contiguous data. my X axis data is always row 1. the code below works but only gets source data from one row

Code:
chrt. Set SourceData Source := .Range (.Cells (I,1), .Cells (I, LastColumn))

so the generated charts picks out its source data s A2: to LastColumn. Then A3: to LastColumn (I to LastColumn) and so on until the last row of data is reached. the charts are generated but the source data is wrong as the data is non contiguous. if my data was static and non contiguous the code below is an example of what i need bt am having problems with:

Code:
chrt.SetSourceData Source:= . Rage ("A1:AD1, A4AD4")

so the first code above is partly what I want but i need something like below but my code does not work

Code:
chrt.SetSourceData Source:= .Range (.Cells (I, 1): (I, LastColumn), (.Cells (1,1): (1, Lastcolumn)) (

any help appreciated
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi

Your statement has several syntax errors.

If I understand correctly it should be:

Code:
    chrt.SetSourceData Source:= _
        Union(.Range(.Cells(I, 1), .Cells(I, Lastcolumn)), .Range(.Cells(1, 1), .Cells(1, Lastcolumn)))
 
Upvote 0
Hi

Your statement has several syntax errors.

If I understand correctly it should be:

Code:
    chrt.SetSourceData Source:= _
        Union(.Range(.Cells(I, 1), .Cells(I, Lastcolumn)), .Range(.Cells(1, 1), .Cells(1, Lastcolumn)))

pgc01 - many thanks. just what I needed. I do have some chart title errors but I will try to fix these. your code correction takes me 90% of the way and is greatly appreciated
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top