✔ 最佳答案
假設沒有 「:」符
A欄:同學名稱
B欄:資料
Sub x2()
Dim arr(1 To 10000, 1 To 6)
Dim R As Integer
Dim NR As Long: NR = [A65536].End(xlUp).Row()
Dim lastdata As String: lastdata = ""
If NR < 3 Then
MsgBox "當前工作表不含資料,程式結束"
Exit Sub
End If
For R = 1 To NR
dat = Trim(Cells(R, 1).Value)
If dat = "" Then GoTo 112
If Not lastdata = dat Then
lastdata = dat
counter = counter + 1
arr(counter, 1) = dat
End If
dat = Trim(Cells(R, 2).Value)
If dat Like "[12]#" Then
arr(counter, 2) = dat
ElseIf dat Like "#[A-Za-z]" Then
arr(counter, 3) = dat
ElseIf dat Like "###[Cc][Mm]" Then
arr(counter, 4) = dat
ElseIf dat Like "##[Kk][Gg]" Then
arr(counter, 5) = dat
Else
arr(counter, 6) = dat
End If
112 ' next row
Next
Sheets.Add.Name = "NewlyGeneratedSheet"
[A2].Resize(counter, 6) = arr
[A1].Resize(1, 5) = Split("學生 年齡 班別 身高 體重")
Rows(2).Select
ActiveWindow.FreezePanes = True
End Sub
2009-04-21 21:03:26 補充:
arr(counter, 6) = dat 防你有額外資料,也一併抄過去。