Sub test()
Dim arr, brr
arr = Range("A1").CurrentRegion.Value
ReDim brr(1 To 9)
For i = 2 To UBound(arr)
For j = 2 To UBound(arr, 2)
If j = 2 And arr(i, j) <> "" Then '开始时间判断
key1 = 2
ElseIf j <> 2 And arr(i, j) <> "" And arr(i, j - 1) = "" Then
key1 = j
End If
If j = UBound(arr, 2) And arr(i, j) <> "" Then '结束时间判断
key2 = j
ElseIf j = UBound(arr, 2) And arr(i, j) = "" Then
Exit For
ElseIf arr(i, j + 1) = "" And arr(i, j) <> "" Then
key2 = j
End If
If key1 <> 0 And key2 <> 0 Then '结果输出
If brr(i - 1) = "" Then
- 1) = Split(arr(1, key1), "-")(0) & "-" & Split(arr(1, key2), "-")(1)
Else
- 1) = brr(i - 1) & "," & Split(arr(1, key1), "-")(0) & "-" & Split(arr(1, key2), "-")(1)
End If
key1 = 0: key2 = 0
End If
Next j
Next i
1) = Application.Transpose(brr)
End Sub
好了,本期教程就到这里啦,走过路过的点个关注分享一下吧,谢谢啦