我正在尝试使用范围将每个工作表中从3到7连接的动态范围连接到一个单独的工作表,这样我就不会弄乱剪贴板了。我能够检测到我要复制的范围,但将其分配给另一个范围一直存在问题。
这一行有什么问题:?
Sheets("Consolidar Datos").Range(ConsolidaArea).Value = Sheets(I).Range(NEW_area).Value
两个范围都是完全相同的大小,但我仍然得到“应用程序定义或对象定义的错误”。
要在工作表#3: B8:O16
工作表"Consolidar Datos": B6:O14
要在工作表#4: B8:O12
工作表"Consolidar Datos": B15:O19
谢谢!
For I = 3 To 7
Set sh = Sheets(I)
With ActiveSheet
Set area = .Range("C8:O33")
LastRow = Last(1, area)
If LastRow <> 0 Then
CopyRange = "B8:" & "O" & LastRow
Set NEW_area = .Range(CopyRange)
If FirstTime = 0 Then
CountRows = CountRows - 1 + NEW_area.Rows.Count
FirstTime = FirstTime + 1
Else
CountRows = CountRows + NEW_area.Rows.Count
End If
ConsolidaCopyRange = StartCell & ":O" & CountRows
Set ConsolidaArea = .Range(ConsolidaCopyRange)
Sheets("Consolidar Datos").Range(ConsolidaArea).Value = _
Sheets(I).Range(NEW_area).Value
StartCell = "B" & CountRows + 1
End If
End With
Next I
答案 0 :(得分:0)
尝试使用以下代码:
For I = 3 To 7
With Sheets(I)
Set area = .Range("C8:O33")
LastRow = Last(1, area)
If LastRow <> 0 Then
CopyRange = "B8:" & "O" & LastRow
Set NEW_area = .Range(CopyRange)
If FirstTime = 0 Then
CountRows = CountRows - 1 + NEW_area.Rows.Count
FirstTime = FirstTime + 1
Else
CountRows = CountRows + NEW_area.Rows.Count
End If
ConsolidaCopyRange = StartCell & ":O" & CountRows
Set ConsolidaArea = Sheets("Consolidar Datos").Range(ConsolidaCopyRange)
ConsolidaArea.Value = NEW_area.Value
StartCell = "B" & CountRows + 1
End If
End With
Next I