VBA to add data to existing plots in different tab

javierdrm

New Member
Joined
Jun 17, 2015
Messages
1
Hi,

First time using this forum.

I want to create a macro to add a set of data to four different plots. The data is located on a different sheet than the plots. The main thing is that I need the input of the data sheet in the macro to be dynamic, as it the plot could be populated from numerous sheets.

I have a macro to copy the template sheet, I then populate the the new sheet, after which I want a macro that plots the new to four plots located on a sheet called "Plot" (original, I know).

I hope it makes sense.

Thanks in anticipation.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi and welcome to the Board

We could use a user form with a RefEdit control to pick ranges, but I'm proposing a simpler method for now:

Code:
Sub Javier()
Dim ser As Series, co As ChartObject, sr, inp$, i%
inp = Application.InputBox("Example: Sheet1!d4:d9", _
"Enter new data address:", "Sheet2!h7:h12", , , , , 2)
sr = Split(inp, "!")
For i = 1 To 4                                      ' loop the charts
    Set co = Sheets("Plot").ChartObjects(i)
    Set ser = co.Chart.SeriesCollection.NewSeries   ' add series
    ser.XValues = "='Plot'!f15:f20"                 ' same for all
    ser.Values = "='" & sr(0) & "'!" & sr(1)
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,326
Messages
6,054,745
Members
444,748
Latest member
knowak87

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