【发布时间】:2015-09-13 20:46:32
【问题描述】:
由于某种原因,我收到了一个错误,但我找不到原因。它发生在复制/粘贴上,但我不知道它是如何导致的。请帮忙
Sub CopyMain()
RowCountBack = 2
Dim n As Integer
RowCount = RowCount / 2
RowCountConst = RowCount
RowCount = RowCount + 1
For n = 1 To 100
'If Cells(RowCount, 10).Value = "AR_Mag (ppm)" Then
If InStr(1, Worksheets("RAW").Cells(RowCount, 7).Value, "AR_Mag", vbTextCompare) > 0 Then
'Sheets("RAW").Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy
WkSht.Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Copy Destination:= _
Worksheets("AR_MAG").Range("a5") _
.End(xlDown).Offset(2, 0)
RowCount = RowCount + RowCountConst
RowCountBack = RowCountBack + RowCountConst
End If
这是经过大量编辑后的代码。原文在这里也有类似的错误
If InStr(1, Worksheets("RAW").Cells(RowCount, 7).Value, "AR_Rot", vbTextCompare) > 0 Then
wkb.Sheets("AR_ROT").Range(Cells(RowCountBack, 1), Cells(RowCount, 10)).Value = wkb.Sheets("RAW").Range(Cells(RowCountBack, 1), Cells(RowCount, 10))
RowCount = RowCount + RowCountConst
RowCountBack = RowCountBack + RowCountConst
End If
如您所见,两个 if 的作用相似
【问题讨论】:
标签: vba excel error-handling copy-paste