|
▼(m´・ω・`)m さん:
連投の参加賞狙いで恐縮です。
Dictionaryを使わず、ループ数もちょっと減らしました。
Sub Sample3()
Dim x As Long
Dim y As Long
Dim j As Long
Dim c As Range
Dim r As Range
Dim dk As Variant
Dim v() As Variant
Dim m As Long
Dim n As Long
Dim k As Long
With ActiveSheet.UsedRange
x = .Columns.Count
y = .Rows.Count
Set r = .Cells.Offset(1).Resize(.Rows.Count - 1)
End With
ReDim v(1 To x * y, 1 To 2)
For Each c In r
dk = c.Value
If Not IsNumeric(Application.Match(dk, WorksheetFunction.Index(v, 0, 1), 0)) And Len(dk) > 0 Then
m = 0
n = 0
For j = 1 To x
If IsNumeric(Application.Match(dk, Columns(j), 0)) Then
n = n + 1
Else
n = 0
End If
m = WorksheetFunction.Max(m, n)
Next
If m > 1 Then
k = k + 1
v(k, 1) = dk
v(k, 2) = m
End If
End If
Next
If k > 0 Then Cells(1, x + 2).Resize(k, 2).Value = v
Set r = Nothing
End Sub
|
|