Private Sub CommandButton1_Click()
Dim r As Range
Dim f As Boolean
' 中是为了测试,所以写得比较简单!!
For i = 1 To 7
If i = 1 Then
Set r = Cells(i, 1)
r.Select
Else
If Cells(i, 1) = Cells(i - 1, 1) Then
Set r = Union(r, Cells(i, 1))
r.Select
f = True
Else
'发现不再连续相同,且已经找到过,就结束,这样用来返回第一次连续相同的值。
If f = True Then
Exit For
End If
'如果之前没找到过,把这当前的单元格选中。
Set r = Cells(i, 1)
r.Select
End If
End If
Next
End Sub