Sub 轉換()
Dim Arr, i&, j%, T$
Arr = Range([C1], [A65536].End(xlUp))
For i = 2 To UBound(Arr)
For j = 1 To 3
T = Arr(i, j)
If Arr(1, j) = "年資" Then
T = Application.Text(Replace(Replace(Replace(T, "日", ""), "月", ":"), "年", ":"), "[hh]年mm月ss日")
ElseIf Arr(1, j) = "組別" And T Like "*[A-z]組*" Then
T = Left(T, Len(T) - 2)
End If
Arr(i, j) = T
Next j
Next i
[A:C].NumberFormatLocal = "@"
[A1:C1].Resize(UBound(Arr)) = Arr
End Sub
那,如果我的檔案,不只有 姓名,組別,年資。還有出生 年月日、住址、電話等等
也就是欄,已經不只3欄了,我要自動偵測有幾欄
目前我的寫法是
多設一個K
k = Range("A1", Range("A1").End(xlToRight)).Count
For i = 2 To UBound(Arr)
For j = 1 To k
這樣我測試是都正常,可以找出到底用了幾欄,並且每一欄都會檢查到
不曉得
Arr = Range([C1], [A65536].End(xlUp))
For i = 2 To UBound(Arr)
跟
k = Range("A1", Range("A1").End(xlToRight)).Count
For j = 1 To k
跟
.UsedRange.Rows.Count