|
こんにちは
お試しを(Sheet2=集計シートのレイアウトもコード化してあります)
Sub test()
Dim Sh As Worksheet, R As Range, C As Range
Dim Fi As Range, Ad As String, Ma As Variant, Da As String
Set Sh = Worksheets("Sheet2")
Sh.Cells.ClearContents
Sh.Range("B1").Value = "4月"
Sh.Range("B1").AutoFill Destination:=Sh.Range("B1:M1"), Type:=xlFillDefault
With Worksheets("Sheet1")
.Columns(1).AdvancedFilter xlFilterCopy, , Sh.Range("A1"), True
Set R = Sh.Range("A2", Sh.Range("A65536").End(xlUp))
For Each C In R
Set Fi = .Columns(1).Find(C.Value, , xlValues, xlWhole)
If Not Fi Is Nothing Then
Ad = Fi.Address
Do
Set Fi = .Columns(1).FindNext(Fi)
Da = Month(Fi.Offset(, 1))
Ma = Application.Match(Da & "月", Sh.Rows(1), 0)
If Not IsError(Ma) Then
C.Offset(, Ma - 1).Value = Fi.Offset(, 2).Value
End If
Loop Until Ad = Fi.Address
End If
Set Fi = Nothing
Next C
Set R = Nothing:Set Sh = Nothing
End With
End Sub
|
|