Public Sub SubName()
Dim ws As Worksheet
Dim iCounter As Long
Dim wso As Worksheet
Dim rw As Long
Dim lastrow As Long
Set wso = Sheets("Master")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "*" & "danger" & "*" Then
ws.Select
lastrow = ws.Cells(Rows.Count, 4).End(xlUp).Row
For iCounter = 2 To lastrow
If ws.Cells(iCounter, 8) < 0.15 And ws.Cells(iCounter, 8) > -0.1 Then
ws.Cells(iCounter, 8).EntireRow.Copy
rw = wso.Cells(wso.Rows.Count, "A").End(xlUp).Row + 1
wso.Cells(rw, 1).PasteSpecial Paste:=xlPasteAll
End If
Next iCounter
End If
Next ws
End Sub
这就是代码的作用:
答案 0 :(得分:0)
尝试将行从一个工作表复制到另一个工作表(不同行上的每一行):
Dim i, lastRow as Integer
Dim wso, ws, copyFrom as Worksheet
Set wso = Sheets("Master")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "*" & "danger" & "*" Then
copyFrom = ws.Select
End if
lastRow = Sheets(copyFrom).Range("A" & Rows.Count).End(xlUp).Row
For i=1 to lastRow
If <--your criteria--> then
ThisWorkbook.Sheets(copyFrom).Rows(i).EntireRow.Copy Destination:=ThisWorkbook.Sheets(wso).Rows(i)
End if
Next i
Next ws