#2
by snasui » Wed Apr 18, 2018 7:23 pm

ปรับชื่อชีต curvep-58001A โดยลบวรรคท้ายสุดทิ้งไปครับ
จากนั้นปรับ Code ตามตัวอย่างด้านล่างครับ
Code: Select all
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim strShName As String, s As Object
If Not Intersect(Target, Range("C5:C11")) Is Nothing Then
ActiveCell.Copy Destination:=Sheets("report").Range("A3")
strShName = Sheets("report").Range("a3").Value
End If
ActiveSheet.ChartObjects("display").Activate
For Each s In ActiveChart.SeriesCollection
s.Delete
Next s
With ActiveChart.SeriesCollection
.NewSeries
.NewSeries
.NewSeries
End With
With ActiveChart
.FullSeriesCollection(1).Name = "flow"
.FullSeriesCollection(1).XValues = "='curve" & strShName & "'!T4:XFD4" 'date
.FullSeriesCollection(1).Values = "='curve" & strShName & "'!T5:XFD5" 'flow
.FullSeriesCollection(2).Name = "head"
.FullSeriesCollection(2).XValues = "='curve" & strShName & "'!T4:XFD4" 'date
.FullSeriesCollection(2).Values = "='curve" & strShName & "'!T6:XFD6" 'head
.FullSeriesCollection(3).Name = "motor power"
.FullSeriesCollection(3).XValues = "='curve" & strShName & "'!T4:XFD4" 'date
.FullSeriesCollection(3).Values = "='curve" & strShName & "'!T$7:XFD7" 'motor
End With
End Sub
:D ปรับชื่อชีต curvep-58001A โดยลบวรรคท้ายสุดทิ้งไปครับ
จากนั้นปรับ Code ตามตัวอย่างด้านล่างครับ
[code]
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim strShName As String, s As Object
If Not Intersect(Target, Range("C5:C11")) Is Nothing Then
ActiveCell.Copy Destination:=Sheets("report").Range("A3")
strShName = Sheets("report").Range("a3").Value
End If
ActiveSheet.ChartObjects("display").Activate
For Each s In ActiveChart.SeriesCollection
s.Delete
Next s
With ActiveChart.SeriesCollection
.NewSeries
.NewSeries
.NewSeries
End With
With ActiveChart
.FullSeriesCollection(1).Name = "flow"
.FullSeriesCollection(1).XValues = "='curve" & strShName & "'!T4:XFD4" 'date
.FullSeriesCollection(1).Values = "='curve" & strShName & "'!T5:XFD5" 'flow
.FullSeriesCollection(2).Name = "head"
.FullSeriesCollection(2).XValues = "='curve" & strShName & "'!T4:XFD4" 'date
.FullSeriesCollection(2).Values = "='curve" & strShName & "'!T6:XFD6" 'head
.FullSeriesCollection(3).Name = "motor power"
.FullSeriesCollection(3).XValues = "='curve" & strShName & "'!T4:XFD4" 'date
.FullSeriesCollection(3).Values = "='curve" & strShName & "'!T$7:XFD7" 'motor
End With
End Sub
[/code]