|
これで、どうでしょーか ? こちらのテストではうまくいきましたが。
Sub Test_Count()
Dim MyR As Range, C As Range
Dim MyV As Variant, x As Variant, y As Variant
Application.ScreenUpdating = False
With Sheets("Sheet1")
If .Range("A1").CurrentRegion.ListHeaderRows = 0 Then
.Rows(1).Insert xlShiftDown
.Range("A1:B1").Value = Array("Data1", "Data2")
End If
.Range("A1", .Range("A65536").End(xlUp)).AdvancedFilter _
xlFilterCopy, , Sheets("Sheet2").Range("A1"), True
.Range("B1", .Range("B65536").End(xlUp)).AdvancedFilter _
xlFilterCopy, , Sheets("Sheet2").Range("B1"), True
If .Range("A1").Value = "Data1" Then
.Rows(1).Delete xlShiftUp
Set MyR = .Range("A1", .Range("A65536").End(xlUp))
Else
Set MyR = .Range("A2", .Range("A65536").End(xlUp))
End If
End With
With Sheets("Sheet2")
.Range("A1").ClearContents
With .Range("B2", .Range("B65536").End(xlUp))
MyV = WorksheetFunction.Transpose(.Value)
.ClearContents
End With
.Range("B1").Resize(, UBound(MyV)).Value = MyV
For Each C In MyR
x = Application.Match(C.Value, .Range("A:A"), 0)
y = Application.Match(C.Offset(, 1).Value, .Rows(1), 0)
.Cells(x, y).Value = .Cells(x, y).Value + 1
Next
.Activate
End With
Application.ScreenUpdating = True: Set MyR = Nothing
End Sub
|
|