Sub test_20190702()
Sheets("Sheet1(自動增加並放置AC及EC料").Select
ROW1 = Cells(Rows.Count, "C").End(3).Row
If ROW1 > 2 Then
Range(Cells(1, "C"), Cells(ROW1, "E")).Clear
End If
For j = 1 To UBound(arr)
If Cells(i, "A") Like arr(j, 1) Then
Rows(i).Delete
GoTo 1100
End If
Next
For j = 1 To UBound(brr)
If Cells(i, "A") Like brr(j, 1) Then
Rows(i).Delete
GoTo 1100
End If
Next
1100:
Next
End Sub
[attach]30979[/attach]作者: cclo0728 時間: 2019-7-4 08:04
簡化一下程式碼:
Sub test_20190702_1()
Dim i%, j%, xR As Range
Sheets(1).[A:C].Copy Sheets(4).[C:E] '複製全部資料至Sheet4(剩餘料號)
For i = 2 To 3
With Sheets(i)
.[C:E].Clear '清除原有資料
Set xR = Range(.[A1], .Cells(Rows.Count, 1).End(xlUp)) '進階篩選準則範圍
Sheets(1).[A:C].AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=xR, CopyToRange:=.[C1], Unique:=False '進階篩選複製
End With
For j = 2 To xR.Count
Sheets(4).[C:C].Replace xR(j), "", Lookat:=xlWhole '依篩選準則文字, 將Sheet4料號取代為空白
Next j
Next i
On Error Resume Next '略過程式錯誤而不中斷
Sheets(4).[C:C].SpecialCells(xlCellTypeBlanks).EntireRow.Delete 'Sheet4 定位C欄[編輯>到>空白格]並刪除, 即為剩餘料號
On Error GoTo 0 '恢復程式錯誤檢測與警告
End Sub
Sub 各別將廠商分頁()
f1 = Sheets.Count '判斷現在有幾頁
ROW1 = Cells(Rows.Count, "A").End(3).Row
If ROW1 > 2 Then
Range(Cells(1, "A"), Cells(ROW1, "B")).Clear
End If
If f1 > 3 Then '判斷頁面大於3頁 表示有原來的資料 刪除
For i = f1 To 4 Step -1 '從最後一頁往前 刪除
Application.DisplayAlerts = False '關閉提醒
Sheets(i).Delete
Application.DisplayAlerts = True '開啟提醒
Next
End If