以前利用していたVBA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
Sub Cp() Application.ScreenUpdating = False Application.EnableEvents = False Application.Calculation = xlCalculationManual For Each w In Sheets If w.Name = "集計" Then Sheets("集計").Delete Next w Sheets.Add Before:=Sheets(1) ActiveSheet.Name = "集計" For Each w In Worksheets If w.Name <> "集計" And w.Name <> "注文書" And w.Name <> "マスタ" Then If Sheets("集計").UsedRange.Rows.Count = 1 Then r = 1 Else r = Sheets("集計").UsedRange.Rows.Count + 1 End If w.UsedRange.Copy Sheets("集計").Cells(r, 1).PasteSpecial Paste:=xlPasteValues Sheets("集計").Cells(r, 1).PasteSpecial Paste:=xlPasteFormats Application.CutCopyMode = False w.UsedRange.ClearContents End If Next w c = 16 '材料/外注 = 19, 運送=16 k = 2 For i = 1 To Sheets("集計").UsedRange.Rows.Count Application.StatusBar = "重複削除中 ... " & i If Sheets("集計").Cells(k, c).Value = "" Or Sheets("集計").Cells(k, c).Value = 0 Or IsNumeric(Sheets("集計").Cells(k, c).Value) = False Then Sheets("集計").Rows(k).Delete Else k = k + 1 End If Next i For Each w In Sheets If w.Name <> "集計" Then w.Delete Next w Application.StatusBar = False Application.ScreenUpdating = True Application.EnableEvents = True Application.Calculation = xlCalculationAutomatic MsgBox "done" End Sub |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
Dim supRange As Range Sub MainLoop() ' アクティブシートで動作するので注意 Call SetMasterRange Set w = ActiveSheet r = 3 Do While w.Cells(r, 2).Value <> "" If MasterLoop(w.Cells(r, 2).Value, w.Cells(r, 3).Value) = False Then MsgBox r & "行にエラーがあります。" Exit Sub End If r = r + 1 Loop End Sub Sub SetMasterRange() ' 行末ハードコーディングしているので注意 Set w = Sheets("マスタ") Set supRange = w.Range("B2:C121") End Sub Function MasterLoop(supCode, supName) For r = 2 To supRange.Rows.Count If supRange.Cells(r, 3).Value = supName And supRange.Cells(r, 2).Value = supCode Then MasterLoop = True Exit Function End If Next MasterLoop = False End Function |