我正在从单独的工作表中复制多个图表并将它们全部粘贴到一个工作表中。
当我在中断模式中逐行执行代码时,一切正常。
当我运行宏时,它会跳过图表,只是表现不稳定
我已经尝试了很多复制和粘贴的方法,但它似乎没有用。
任何想法有什么不对?
我正在从带有列表框的用户表单中提取要复制的图表名称。
这是我试图用来复制图表的当前代码:
For i = 0 To frmCustomChart.lstChartNames.ListCount - 1
If frmCustomChart.lstChartNames.Selected(i) Then
copyChartName = frmCustomChart.lstChartNames.List(i)
Set copySheet = Sheets(copyChartName)
For Each copychart In copySheet.ChartObjects
copychart.Activate
ActiveChart.ChartArea.Copy
pasteSheet.Activate
pasteSheet.Cells(pasteRow, pasteCol).Select
pasteSheet.Paste
pasteSheet.Range("A1").Select
pasteCol = pasteCol + 11
Next copychart
End If
Next i
ActiveSheet.Range("A1").Select
Application.ScreenUpdating = True
答案 0 :(得分:0)
试试这个。我只是简化了你的代码并纠正了图表行的复制。
Dim copychart As ChartObject, i As Long, pasteRow As Long, pasteCol As Long
pasteRow = 1: pasteCol = 1 'Just initializing variable
With frmCustomChart.lstChartNames
For i = 0 To .ListCount - 1
If .Selected(i) Then
Set copySheet = Sheets(.List(i))
For Each copychart In copySheet.ChartObjects
copychart.Chart.ChartArea.Copy 'I think this is the correct one
pasteSheet.Cells(pasteRow, pasteCol).Activate
pasteSheet.Paste
pasteCol = pasteCol + 11
Next copychart
End If
Next i
End With