VBA. 批量复制sheet内指定内容
背景:一个excel内有包含0-18序号的Sheet,需要将1-18的sheet内包含标准差的行复制到sheet”0“中。
方法:
- 从1-18遍历sheet,找到单元格值为”标准差“的行,
- 然后(仅复制值)复制该行到指定sheet内
结果:

Sub CopyStdevRowsToSheet0()
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim stdevRow As Long
Dim found As Boolean
Dim sheetIndex As Long
Dim destRow As Long
Set wsDest = ThisWorkbook.Sheets("0")
destRow = 1
For sheetIndex = 1 To 18
Set wsSource = ThisWorkbook.Sheets(CStr(sheetIndex))
found = False
For i = 1 To 100
For j = 1 To 10
If wsSource.Cells(i, j).Value = "标准差" Then
found = True
stdevRow = i
Exit For
End If
Next j
If found Then Exit For
Next i
If found Then
wsSource.Cells(stdevRow, 1).Value = sheetIndex
wsDest.Rows(destRow).Value = wsSource.Rows(stdevRow).Value
destRow = destRow + 1
End If
Next sheetIndex
End Sub