fork download
  1. Option Explicit
  2.  
  3. Public Sub 納品対象外部品()
  4. Dim ws As Worksheet
  5. Dim lastRow As Long
  6. Dim wrow As Long
  7. Dim no_blk As Long
  8. Dim str As String
  9. Dim bno As Long
  10. Dim ino As Long
  11. Set ws = ActiveSheet
  12. lastRow = ws.Cells(Rows.Count, 1).End(xlUp).row
  13. If lastRow < 4 Or (lastRow - 1) Mod 3 <> 0 Then
  14. Call error(ws, lastRow, "最終行不正")
  15. End If
  16. no_blk = (lastRow - 1) \ 3
  17. ws.Range("B2:B" & lastRow).ClearContents
  18. For bno = 1 To no_blk
  19. Dim rowA As Long: rowA = 0
  20. Dim rowB As Long: rowB = 0
  21. Dim rowH As Long: rowH = 0
  22. Dim row_mark As Long: row_mark = 0
  23. Dim pv_wd As String: pv_wd = ""
  24. Dim en_wd As String
  25. For ino = 1 To 3
  26. wrow = (bno - 1) * 3 + ino + 1
  27. str = ws.Cells(wrow, 1).Value
  28. Dim wd As String
  29. Select Case Right(str, 1)
  30. Case "A"
  31. If rowA <> 0 Then Call error(ws, wrow, "終端文字Aが2回出現")
  32. rowA = wrow
  33. wd = Left(str, Len(str) - 1)
  34. Case "B"
  35. If rowB <> 0 Then Call error(ws, wrow, "終端文字Bが2回出現")
  36. rowB = wrow
  37. wd = Left(str, Len(str) - 1)
  38. Case "H"
  39. If rowH <> 0 Then Call error(ws, wrow, "終端文字Hが2回出現")
  40. rowH = wrow
  41. en_wd = Right(str, 2)
  42. Select Case en_wd
  43. Case "AH"
  44. Case "BH"
  45. Case Else
  46. Call error(ws, wrow, "終端文字がAH,BHの何れかでない")
  47. End Select
  48. wd = Left(str, Len(str) - 2)
  49. Case Else
  50. Call error(ws, wrow, "終端文字がA,B,Hの何れかでない")
  51. End Select
  52. If pv_wd = "" Then
  53. pv_wd = wd
  54. Else
  55. If pv_wd <> wd Then Call error(ws, wrow, "部番の共通文字が不一致")
  56. End If
  57. Next
  58. If en_wd = "AH" Then row_mark = rowA
  59. If en_wd = "BH" Then row_mark = rowB
  60. If row_mark = 0 Then Call error(ws, wrow, "納品対象外行が決定できない")
  61. ws.Cells(row_mark, 2).Value = "-"
  62. Next
  63. MsgBox ("完了")
  64. End Sub
  65. Private Sub error(ws As Worksheet, ByVal rowNo As Long, ByVal msg As String)
  66. ws.Cells(rowNo, 1).Select
  67. MsgBox (msg)
  68. End
  69. End Sub
  70.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty