Tạo Chart tự động (2 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

hadoan-pap

Thành viên tiêu biểu
Tham gia
8/7/15
Bài viết
461
Được thích
20
Chào mọi ng!

Em có đoạn code bên dưới mà nó báo sai 2 dòng… mục đích của em là chọn dòng cuối cùng và cột cuối cùng có dữ lieu để tạo chart.

Mọi người check giúp em với ạ.

E xin cảm ơn!

Dim rng As Range
Dim cht As Object
Dim i, j As Integer

For i = 1 To 50
For j = 1 To 100

If Sheet1.Cells(i, 1) <> "" Then
If Sheet1.Cells(1, j) <> "" Then

'Your data range for the chart
Set rng = ActiveSheet.Range(Cells(i - 1, 1), Cells(1, j - 1)) ====> Dòng này sai

'Create a chart
Set cht = ActiveSheet.Shapes.AddChart2
cht.Name = "Chart 18"

'Give chart some data
cht.Chart.SetSourceData Source:=rng

'Determine the chart type
cht.Chart.ChartType = xlAreaStacked

ActiveSheet.ChartObjects("Chart 18").Activate
ActiveChart.Axes(xlCategory).Select
ActiveChart.Axes(xlCategory).CategoryType = xlTimeScale
ActiveChart.SeriesCollection(1).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
Range("O19").Select
Application.CommandBars("Format Object").Visible = False
ActiveSheet.ChartObjects("Chart 18").Activate
ActiveSheet.ChartObjects("Chart 18").Activate
''ActiveChart.FullSeriesCollection(1).XValues = "=Sheet1!$A$2:$A$15"
ActiveChart.FullSeriesCollection(1).XValues = ActiveSheet.Range(Sheet1.Cells(j - 1, 1)) ====> Dòng này sai
End If
End If

Next j
Next i
 
Web KT

Bài viết mới nhất

Back
Top Bottom