fork download
  1. Option Explicit
  2. Dim month_sheet As Worksheet '月集計シート
  3. Dim month_row As Long '月集計シートの行番号
  4. Public Sub 日報転記()
  5. Dim wday As Long '日数
  6. month_row = 3
  7. Set month_sheet = Worksheets("月集計")
  8. '月集計の3行目以降をクリア
  9. month_sheet.Rows("3:" & Rows.count).ClearContents
  10. '1日~31日まで繰り返す
  11. For wday = 1 To 31
  12. '1日分の日報シートを転記
  13. Call set_1day(wday)
  14. Next
  15. MsgBox ("完了")
  16. End Sub
  17. '1日分の日報シート転記
  18. Private Sub set_1day(ByVal wday As Long)
  19. Dim ws As Worksheet
  20. Dim lastRow As Long
  21. Dim wrow As Long
  22. '指定日(wday)に対応する日報シートを取得する
  23. Call get_day_sheet(wday, ws)
  24. lastRow = ws.Cells(Rows.count, "B").End(xlUp).Row 'B列の最終行取得
  25. For wrow = 5 To lastRow
  26. 'A列が●のみ転記する
  27. If ws.Cells(wrow, "A").Value <> "" Then
  28. '月集計シートへ転記
  29. month_sheet.Cells(month_row, "A").Resize(1, 13).Value = ws.Cells(wrow, "B").Resize(1, 13).Value
  30. month_row = month_row + 1
  31. End If
  32. Next
  33. End Sub
  34. '指定日(wday)に対応する日報シートを取得する
  35. Private Sub get_day_sheet(ByVal wday As Long, ByRef ws As Worksheet)
  36. Dim sname As String
  37. Dim i As Long
  38. sname = wday & "日"
  39. For i = 1 To Worksheets.count
  40. If Worksheets(i).Name = sname Then
  41. Set ws = Worksheets(i)
  42. Exit Sub
  43. End If
  44. Next
  45. MsgBox ("日報シート【" & sname & "】がありません")
  46. End
  47. End Sub
  48.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty