Sub test()
Dim Arr, Brr(), a, w$, i&, j%
Columns("R:T").NumberFormatLocal = "@"
Arr = Range([E2], [E2].End(4))
ReDim Brr(1 To UBound(Arr), 1 To 3)
For i = 2 To UBound(Arr)
a = Split(Arr(i, 1), "-")
If UBound(a) < 2 Then GoTo 99
For j = 0 To UBound(a)
w = Split(Arr(i, 1), "-")(j)
If j = 0 Then
If Len(w) < 3 Then Brr(i, 3) = "0" & w & "-" Else Brr(i, 3) = w & "-"
ElseIf j = 1 Then
If Len(w) < 4 Then Brr(i, 2) = "0" & w & "-" Else Brr(i, 2) = w & "-"
ElseIf j = 2 Then
If Len(w) < 3 Then Brr(i, 1) = "0" & w Else Brr(i, 1) = w
End If
Next
99: Next
[R2].Resize(UBound(Brr), 3) = Brr
End Sub作者: PJChen 時間: 2021-7-5 17:34
for i = 2 to ~~
arr的範圍包含第一行標題, 第一行不須處理, 故從2起始~~作者: 准提部林 時間: 2021-7-5 19:34
若都是純數字~~
Sub TEST_A1()
Dim Arr, i&, j%, Vr, TR
Arr = Range([g1], [e65536].End(3))
Vr = Array("000-", "0000-", "000")
For i = 3 To UBound(Arr)
TR = Split(Arr(i, 1) & "--", "-")
For j = 0 To 2
Arr(i - 2, 3 - j) = IIf(IsNumeric(TR(j)), Format(TR(j), Vr(j)), "")
Next j
Next i
With [r3].Resize(UBound(Arr) - 2, 3)
.NumberFormatLocal = "@"
.Value = Arr
End With
End Sub