|
没其他要求就新建表了
- Sub 提取()
- Dim ws As Worksheet
- For Each ws In Worksheets
- If ws.Name = "结果表" Then
- Application.DisplayAlerts = False
- ws.Delete
- Application.DisplayAlerts = True
- Exit For
- End If
- Next ws
-
- Sheets("Sheet1").Copy After:=Sheets(Sheets.count)
- ActiveSheet.Name = "结果表"
-
- Dim resultLastRow As Long
- resultLastRow = Sheets("结果表").Cells(Sheets("结果表").Rows.count, "B").End(xlUp).Row
-
- Dim resultRange As Range
- Set resultRange = Sheets("结果表").Range("B2:B" & resultLastRow)
-
- Dim sheet1LastRow As Long
- sheet1LastRow = Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.count, "D").End(xlUp).Row
-
- Dim sheet1Range As Range
- Set sheet1Range = Sheets("Sheet1").Range("C2:E" & sheet1LastRow)
-
- Dim resultCell As Range
- For Each resultCell In resultRange
- Dim sheet1Cell As Range
- Set sheet1Cell = sheet1Range.Find(resultCell.Value, LookIn:=xlValues, lookat:=xlWhole)
- If Not sheet1Cell Is Nothing Then
- resultCell.Offset(0, 1).Value = sheet1Cell.Offset(0, -1).Value
- resultCell.Offset(0, 2).Value = sheet1Cell.Value
- resultCell.Offset(0, 3).Value = sheet1Cell.Offset(0, 1).Value
- Else
- resultCell.Offset(0, 1).Value = ""
- resultCell.Offset(0, 2).Value = ""
- resultCell.Offset(0, 3).Value = ""
- End If
- Next resultCell
- End Sub
复制代码 |
|