比较两张纸,复制到第三张纸并循环

时间:2018-07-20 18:13:08

标签: vba

我一直在研究此宏,该宏从A2工作表“当前警报”获取值,然后在另一工作表“ ETS警报表”的B列中进行搜索。然后将两行都复制到另一个名为“结果”的工作表中。 我的问题是,它找到第一个值,但随后不会循环并查看A3和A4等。

此外,如果该值不存在于“ ETS警报表”中,则宏将翻转。相反,我希望将其复制到另一个选项卡。

这是我到目前为止所拥有的。

    Option Explicit

Sub testcopy()


'Clear Page
    Sheets("Result").Activate
    Range("B2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp
    Range("B2").Select

'find ets alarms and copy to results tab

Sheets("ETS Alarm Table").Activate
Range("B2:J2").Copy
Sheets("Result").Activate
Range("B2").Select
ActiveSheet.Paste

Sheets("ETS Alarm Table").Activate
ActiveCell.Offset(1, 0).Select
ActiveSheet.Range (cells)
Sheets("Result").Activate
Range("B4").Select
ActiveSheet.Paste

Range("B1").EntireColumn.Find("Eng_TorqueObs").Select
Range(ActiveCell, cells(ActiveCell.Row, ActiveSheet.Columns.count).End(xlToLeft)).Copy
Sheets("Result").Activate
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste

Sheets("ETS Alarm Table").Activate
Range("B1").EntireColumn.Find("Turb_GasInTemp").Select
Range(ActiveCell, cells(ActiveCell.Row, ActiveSheet.Columns.count).End(xlToLeft)).Copy
Sheets("Result").Activate
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste

Sheets("ETS Alarm Table").Activate
Range("B1").EntireColumn.Find("CCV_Press").Select
Range(ActiveCell, cells(ActiveCell.Row, ActiveSheet.Columns.count).End(xlToLeft)).Copy
Sheets("Result").Activate
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste

Sheets("ETS Alarm Table").Activate
Range("B1").EntireColumn.Find("Blowby_GasFlow").Select
Range(ActiveCell, cells(ActiveCell.Row, ActiveSheet.Columns.count).End(xlToLeft)).Copy
Sheets("Result").Activate
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste

'pull in matching current alarms
Sheets("Current Alarms").Activate
Range("A1").EntireColumn.Find("EngineSpeed").Select
Range(ActiveCell, cells(ActiveCell.Row, ActiveSheet.Columns.count).End(xlToLeft)).Copy
Sheets("Result").Activate
Range("B3").Select
ActiveSheet.Paste

Sheets("Current Alarms").Activate
Range("A1").EntireColumn.Find("Eng_TorqueObs").Select
Range(ActiveCell, cells(ActiveCell.Row, ActiveSheet.Columns.count).End(xlToLeft)).Copy
Sheets("Result").Activate
ActiveCell.Offset(2, 0).Select
ActiveSheet.Paste

 cells.Select
    cells.EntireColumn.AutoFit
    cells.EntireRow.AutoFit
    Range("A1").Select


End Sub

Current Alarms

ETS Alarm

Results

0 个答案:

没有答案