Programing VB in excel

[Closed]
Report
-
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
-
Hello,
what if I have 2 columns in 2 different excel sheets and I want to make a button to draw a graph between these 2 colomns what should I do???

1 reply

Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
803
do you want the two charts as different charts in the same sheet.
suppose the data is in C1 down in sheet1
and in D1 down in sheet2

in that run this macro. if the data are in different columns modify the macro suitably
give feedback
the macro is .

Sub test()
Dim rng As Range
On Error Resume Next
ActiveSheet.ChartObjects("mychart").Delete

Charts.Add
ActiveChart.ChartType = xlLineMarkers
 ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("C1:C6"), PlotBy:= _
        xlColumns
ActiveChart.Location where:=xlLocationAsObject, Name:="sheet1"
 ActiveChart.Parent.Name = "mychart"
 Worksheets("sheet2").Activate
 Set rng = Range(Range("d1"), Range("d1").End(xlDown))
rng.Copy
Worksheets("sheet1").Activate
ActiveSheet.ChartObjects("mychart").Select
ActiveChart.SeriesCollection.Paste NewSeries:=True
End Sub