✔ 最佳答案
Private Sub CommandButton1_Click()
Dim TBarray(1 To 13) As Control
For i = 1 To 13
Set TBarray(i) = Controls("TextBox" & i)
TBarray(i) = Application.Text(TBarray(i).Text, "00")
2015-07-18 15:14:48 補充:
Sheets("Sheet3").Cells(i, 1).NumberFormatLocal = "@"
Sheets("Sheet3").Cells(i, 1) = TBarray(i).Text
Next i
End Sub
將上面2段組合試試
2015-07-18 22:18:55 補充:
Private Sub CommandButton1_Click()
Dim TBarray(1 To 13) As Control
For i = 1 To 13
Set TBarray(i) = Controls("TextBox" & i)
TBarray(i) = Application.Text(TBarray(i).Text, "00")
Sheets("Sheet3").Cells(i, 1).NumberFormatLocal = "@"
Sheets("Sheet3").Cells(i, 1) = TBarray(i).Text
Next i
End Sub
試試補充說明:
1.因為版大的TextBox控制項共13個,為省去一個一個的程式設定,故以陣列的方式來達成
2.Dim TBarray(1 To 13) As Control ->定義一個共有13個控制項的陣列
3.Set TBarray(i) = Controls("TextBox" & i) ->把陣列指定為TextBox控制項
4.TBarray(i) = Application.Text(TBarray(i).Text, "00") ->把TextBox控制項的值轉為2位數
5.Sheets("Sheet3").Cells(i, 1).NumberFormatLocal = "@" ->因TextBox控制項的值複製到Sheet3的儲存格時會是數值各式,透過這行把它轉為文字格式