返回列表 上一主題 發帖

[發問] Excel inputbox 迴圈 問題

  1. Sub 請輸入()
  2.     Dim X   As Variant
  3.     Dim Y   As Variant
  4.     Dim C1  As Integer
  5.    
  6. EnterID:
  7.     X = InputBox("請輸入收料OP工號 [ Please enter Operator ID ]", "請輸入收料OP工號  [Please enter Operator ID ]", "")
  8.     If X = False Then Exit Sub
  9. EnterMo:
  10.     Y = InputBox("請輸入MO, 輸入完畢請按取消鍵 [ Please enter MO ]", "請輸入MO [ Please enter MO ]", "")
  11.     If Y = False Then
  12.       If MsgBox("你的輸入有誤,是否重新輸入一個MO?" & vbCrLf & _
  13.                 "點擊""是""重新輸入,""否""退出當次輸入。", vbYesNo Or vbQuestion, "MO輸入錯誤") = vbYes Then GoTo EnterMo
  14.       Exit Sub
  15.     End If
  16.    
  17.     C1 = 2
  18.     While Cells(C1, 2) <> ""
  19.         C1 = C1 + 1
  20.     Wend
  21.     Cells(C1, 1) = X
  22.     Cells(C1, 2) = Y
  23.     Cells(C1, 3) = Now()
  24.     ActiveWorkbook.Save
  25.     GoTo EnterID
  26. End Sub
複製代碼
世界那麼大,可我想去哪?

TOP

回復 1# v03586
上面的代碼有誤,帖子不能編輯,重發一次代碼:
  1. Sub 請輸入()
  2.     Dim X   As String
  3.     Dim Y   As String
  4.     Dim C1  As Long
  5.    
  6. EnterID:
  7.     X = InputBox("請輸入收料OP工號 [ Please enter Operator ID ]", "請輸入收料OP工號  [Please enter Operator ID ]")
  8.     If Len(X) < 1 Then Exit Sub
  9. EnterMo:
  10.     Y = InputBox("請輸入MO, 輸入完畢請按取消鍵 [ Please enter MO ]", "請輸入MO [ Please enter MO ]", "")
  11.     If Len(Y) < 1 Then
  12.       If MsgBox("你的輸入有誤,是否重新輸入一個MO?" & vbCrLf & _
  13.                 "點擊""是""重新輸入,""否""退出當次輸入。", vbYesNo Or vbQuestion, "MO輸入錯誤") = vbYes Then GoTo EnterMo
  14.       Exit Sub
  15.     End If
  16.    
  17.     C1 = 2
  18.     While Cells(C1, 2) <> ""
  19.         C1 = C1 + 1
  20.     Wend
  21.     Cells(C1, 1) = X
  22.     Cells(C1, 2) = Y
  23.     Cells(C1, 3) = Now()
  24.     ActiveWorkbook.Save
  25.     GoTo EnterID
  26. End Sub
複製代碼
世界那麼大,可我想去哪?

TOP

        靜思自在 : 知識要用心體會,才能變成自己的智慧。
返回列表 上一主題