|
フィルターを使わず、IV列に数式を埋めて判定・処理するコードです。
Sub Data_Distribute()
Dim xR As Long, xC As Long
Dim MyR As Range
Application.ScreenUpdating = False
On Error Resume Next
Workbooks("data.xls").Activate
If Err.Number <> 0 Then
Workbooks.Open ThisWorkbook.Path & "\data.xls"
Err.Clear
End If
On Error GoTo 0
With ActiveWorkbook.Worksheets("data")
With .Range("X6").CurrentRegion
xR = .Rows.Count + 5: xC = .Columns.Count
End With
Set MyR = .Range("X7:X" & xR).Resize(, xC)
On Error Resume Next
With Range("IV7:IV" & xR)
.Formula = "=IF(AG7=""OK"",1,IF(AG7=""NG"",""A"",FALSE))"
Intersect(MyR, .SpecialCells(3, 1).EntireRow) _
.Copy ThisWorkbook.Worksheets("B").Range("A6")
Intersect(MyR, .SpecialCells(3, 2).EntireRow) _
.Copy ThisWorkbook.Worksheets("C").Range("A6")
Intersect(MyR, .SpecialCells(3, 4).EntireRow) _
.Copy ThisWorkbook.Worksheets("A").Range("A1")
.ClearContents
End With
End With
With ThisWorkbook
.Activate: .Worksheets("A").Activate
End With
Application.ScreenUpdating = True: Set MyR = Nothing
End Sub
|
|