我在以下代码中收到1004错误:在set range语句中。能不能让我知道我在这里失踪了什么,因为我无法弄明白。
Sub updatechart(Nombre As Variant)
Dim cht As Chart
Dim rng As Range
Dim cmb As ComboBox
Dim Fila As Integer
Dim ser As Series
Dim rng1 As Range
Dim rng2 As Range
Dim rngdata As Range
Dim s As Integer
Worksheets(2).Activate
Set cmb = Sheets(2).ComboBox1
Set cht = ActiveSheet.ChartObjects(1).Chart
Set rngdata = Sheets(1).Range("b6:f370")
semana = cmb.Value
Fila = BuscaPalabra1(semana)
For Each ser In cht.SeriesCollection
ser.Delete
Next
For s = 3 To rngdata.Columns.Count
Set ser = cht.SeriesCollection.NewSeries
Set rng1 = Sheets(1).Range(Cells(Fila, s), Cells(Fila + 7, s))
Set rng2 = Sheets(1).Range(Cells(Fila, 2), Cells(Fila, 2))
With ser
.XValues = rng2
.Values = rng1
'cht.SeriesCollection(contador).Select
' cht.SetSourceData Source:=Sheets("datos").Range("rng1", "rng2")
End With
Next
End Sub
答案 0 :(得分:1)
默认情况下,对常规代码模块(不是工作表代码模块)的Range()
或Cells()
的任何调用都将使用ActiveSheet,因此最好使用特定工作表对所有这些内容进行限定:< / p>
With Sheets(1)
Set rng1 = .Range(.Cells(Fila, s), .Cells(Fila + 7, s))
Set rng2 = .Cells(Fila, 2)
End with
似乎rng1和rng2的大小不同?