Programing VB in excel

Closed
wael - Jun 17, 2009 at 06:50 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jun 17, 2009 at 08:29 PM
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???
Related:

1 response

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Jun 17, 2009 at 08:29 PM
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
0