我有一个包含 200 多个具有相同结构的 Excel 电子表格的工作簿。在这些工作表上,主题的值始终位于单元格 C2 中,日期的值始终位于 C7 中,但对于Root_cause和Solutions,它们从不同的行开始。
我需要在主工作表上复制这些信息并附加它:
也许使用查找功能找到“Root_cause”这个词是个好主意,然后选择右侧的一列并向下拖动以复制所有相关行?
代码:
Sub Protocol()
Dim wsheet As Worksheet
With ThisWorkbook.Sheets("Main")
For Each wsheet In ThisWorkbook.Sheets
If wsheet.Name <> "Main" Then
Set Date = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
Set Theme = .Cells(.Rows.Count, "B").End(xlUp).Offset(1, 0)
Set Root_cause = .Cells(.Rows.Count, "C").End(xlUp).Offset(1, 0)
Set Solutions = .Cells(.Rows.Count, "D").End(xlUp).Offset(1, 0)
Date.Value = wsheet.Range("C7").Value
Theme.Value = wsheet.Range("C2").Value
#Then I need to use FIND function on each sheet, come to word 'Root_cause', choose all rows for Root_cause and Solutions, copy them and append on sheet "Main"
End If
Debug.Print wsheet.Name
Next wsheet
End With
End Sub


