Sub test()
Dim A, B, j, c, jStart, jEnd, length, maxLength, ans
Rows(3) = ""
A = [e2:bn4] '左右多选1列
c = UBound(A, 2)
A(3, 1) = "^"
A(3, c) = "$"
jStart = 2
jEnd = jStart
maxLength = -1
For j = 2 To c
If Len(A(3, j)) > 0 Then
jEnd = j - 1
length = jEnd - jStart + 1
If maxLength <= length Then
If maxLength < length Then ans = "": maxLength = length
ans = ans & ";" & jStart & "," & jEnd
End If
jStart = j + 1
End If
Next
B = VBA.Split(ans, ";")
For i = 1 To UBound(B)
For j = Split(B(i), ",")(0) To Split(B(i), ",")(1)
A(2, j) = A(1, j)
Next
Next
A(3, 1) = ""
A(3, c) = ""
[e2].Resize(UBound(A), UBound(A, 2)) = A
End Sub
|