我正在尝试将行从导入到文档中的选项卡复制到另一个选项卡。
'Clears previous data from sheet
Sheets("60L Specific Data").Select
Cells.Range("A3:AC3000").ClearContents
'Pastes Title Block from Imported into 60L sheet
Sheets("Imported Data").Select
Rows("1:1").Select
Selection.Copy
Sheets("60L Specific Data").Select
Rows("3:3").Select
ActiveSheet.Paste
'Filters using several criteria
Dim i As Integer
Dim j As Integer
j = 4
For i = 2 To 2000
If Cells(i, 28) <> "" Or Cells(i, 29) <> "" Or InStr(Cells(i, 6).Value, "K60") <> 0 Or InStr(Cells(i, 6).Value, "60T") Then
Sheets("Imported Data").Select
Rows(i).Select
Selection.Copy
Sheets("60L Specific Data").Select
Rows(j).Select
ActiveSheet.Paste
j = j + 1
End If
Next i
现在,这个问题使我感到沮丧。有一些测试我知道您想知道的事情:
首先,前两个代码块按预期工作。
其次,如果您删除了if语句,它将起作用。第三,当我替换一个if语句时,我知道它必须对所有人都是正确的,它的确运行了,但是任何只会导致选择某些语句的语句根本不起作用。
我很困惑,为此花了很多时间,请帮忙!
始终更安全/更轻松地使用变量来引用工作表,并避免在以下位置激活/选择:
Dim shtSrc As Worksheet, shtDest As Worksheet
Dim rw As Range
Dim i As Long, j As Long
Set shtSrc = Sheets("Imported Data")
Set shtDest = Sheets("60L Specific Data")
'Clears previous data from sheet
shtDest.Range("A3:AC3000").ClearContents
'Pastes Title Block from Imported into 60L sheet
shtSrc.Rows(1).Copy Destination:=shtDest.Cells(3, 1)
j = 4
'Filters using several criteria
For i = 2 To 2000
Set rw = shtSrc.Rows(i)
If rw.Cells(28) <> "" Or rw.Cells(29) <> "" Or _
InStr(rw.Cells(6).Value, "K60") <> 0 Or _
InStr(rw.Cells(6).Value, "60T") Then
rw.Copy shtDest.Cells(j, 1)
j = j + 1
End If
Next i
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句