你的最后一行,Debug.Print wksPivotData.Range(1, 1).Value
不会打印,因为你用错了Range()
。我猜你想要A1?
使用时Range(1,1)
,你指的是一个不存在的范围。如果你想做单元格A1,你需要
With wksPivotData
myData = .Range(.Cells(1,1),.Cells(1,1)).Value
End with
由于您使用多个工作表,我会使用with
声明如上。写同样的东西的另一种方法是wksPivotData.Range(wksPivotData.Cells(1,1),wksPivotData.Cells(1,1))
(使用时需要明确告诉Excel要引用哪个工作表Range()
and cells()
.
最后,对于您的调整大小,如果我没记错的话,您将必须添加相同的内容Cell()
两次在你的范围内:
wksPivotData.Range(wksPivotData.Cells(CurrentRow, 1),ksPivotData.Cells(CurrentRow, 1)).Resize(tbl.ListRows.Count, tbl.ListColumns.Count).Value = _
tbl.Range.Value
或者,对于同一件事,但采取不同的方式:
With wksPivotData
.Range(.Cells(currentRow, 1), .Cells(currentRow, 1)).Resize(tbl.ListedRows.Count, tbl.ListColumns.Count).Value = tbl.Range.Value
End With