fork download
  1. Option Explicit
  2.  
  3. Public Sub 単価表設定()
  4. Dim ws As Worksheet '作業シート
  5. Dim wrow As Long '処理行
  6. Dim wcol As Long '
  7. Dim trg_col As Long '○のある列
  8. Dim trg_row As Long '○のある列に一致する祝日の行(カレンダー内)
  9. Dim hol_col As Long '○のある列に一致する祝日の列(I,J,Kの何れかの列)
  10. Dim result As Boolean
  11. Set ws = ActiveSheet
  12. For wrow = 8 To 9
  13. result = find_maru(ws, wrow, trg_col)
  14. If result = False Then
  15. MsgBox (ws.Cells(wrow, "A").Value & "に○がありません")
  16. GoTo NEXT99
  17. End If
  18. result = find_holiday(ws, trg_col, trg_row, hol_col)
  19. If result = False Then
  20. MsgBox (ws.Cells(wrow, "A").Value & "の○のある列に一致する祝日がありません")
  21. GoTo NEXT99
  22. End If
  23. result = set_tanka(ws, wrow, trg_col, trg_row, hol_col)
  24. If result = False Then
  25. MsgBox (ws.Cells(wrow, "A").Value & "の単価設定は失敗しました")
  26. End If
  27. NEXT99:
  28. Next
  29. MsgBox ("完了")
  30. End Sub
  31.  
  32. '指定行の○を探す
  33. Private Function find_maru(ByVal ws As Worksheet, ByVal wrow As Long, trg_col As Long) As Boolean
  34. Dim wcol As Long
  35. find_maru = False
  36. 'B~H列まで検索
  37. For wcol = 2 To 8
  38. If ws.Cells(wrow, wcol).Value = "○" Then
  39. trg_col = wcol
  40. find_maru = True
  41. Exit Function
  42. End If
  43. Next
  44. End Function
  45.  
  46. '指定列の休日を探す
  47. Private Function find_holiday(ByVal ws As Worksheet, ByVal trg_col As Long, trg_row As Long, hol_col As Long) As Boolean
  48. Dim wrow As Long
  49. Dim hcol As Long
  50. find_holiday = False
  51. For wrow = 3 To 7
  52. If ws.Cells(wrow, trg_col).Value <> "" Then
  53. For hcol = 9 To 11
  54. If ws.Cells(wrow, trg_col).Value = ws.Cells(3, hcol).Value Then
  55. trg_row = wrow
  56. hol_col = hcol
  57. find_holiday = True
  58. Exit Function
  59. End If
  60. Next
  61. End If
  62. Next
  63. End Function
  64.  
  65. '指定列、指定行の次の日から月末まで単価A*を探し、設定する。(祝日はスキップする)
  66. Private Function set_tanka(ByVal ws As Worksheet, ByVal mst_row As Long, ByVal trg_col As Long, ByVal trg_row As Long, ByVal hol_col As Long) As Boolean
  67. Dim flag As Boolean
  68. Dim result As Boolean
  69. Dim hcol As Long
  70. set_tanka = False
  71. result = next_day(ws, trg_col, trg_row)
  72. Do While result = True
  73. flag = False
  74. For hcol = 9 To 11
  75. If ws.Cells(trg_row, trg_col).Value = ws.Cells(3, hcol).Value Then
  76. flag = True
  77. End If
  78. Next
  79. If flag = False And Left(ws.Cells(mst_row, trg_col).Value, 1) = "A" Then
  80. ws.Cells(mst_row, hol_col) = ws.Cells(mst_row, trg_col).Value
  81. set_tanka = True
  82. Exit Function
  83. End If
  84. result = next_day(ws, trg_col, trg_row)
  85. Loop
  86. End Function
  87.  
  88. '指定列、指定行の次の日から単価A*を探し、設定する
  89. Private Function next_day(ByVal ws As Worksheet, trg_col As Long, trg_row As Long) As Boolean
  90. next_day = False
  91. trg_col = trg_col + 1
  92. If trg_col > 8 Then
  93. trg_col = 2
  94. trg_row = trg_row + 1
  95. End If
  96. If trg_row > 7 Then Exit Function
  97. If ws.Cells(trg_row, trg_col).Value = "" Then Exit Function
  98. next_day = True
  99. End Function
  100.  
  101.  
  102.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty