Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何打开第二个输入框,然后再打开另一个Excel VBA输入框_Vba_Excel_Inputbox - Fatal编程技术网

如何打开第二个输入框,然后再打开另一个Excel VBA输入框

如何打开第二个输入框,然后再打开另一个Excel VBA输入框,vba,excel,inputbox,Vba,Excel,Inputbox,这是一个非常新的问题,但我似乎无法让它发挥作用。选择单元格(“A501”)后,我想提示用户输入一个数字。然后我想在单元格(“Y501”)中输入用户输入的号码。提供该数字后,我希望出现第二个输入框(“输入立方:”),其值将自动放置在单元格(“Z501”)中。这是我在sheet2上的代码,目前不起作用 Private Sub CommandButton1_Click() Call RunallMacros End Sub Option Explicit Sub Worksheet_Sel

这是一个非常新的问题,但我似乎无法让它发挥作用。选择单元格(“A501”)后,我想提示用户输入一个数字。然后我想在单元格(“Y501”)中输入用户输入的号码。提供该数字后,我希望出现第二个输入框(“输入立方:”),其值将自动放置在单元格(“Z501”)中。这是我在sheet2上的代码,目前不起作用

Private Sub CommandButton1_Click()
    Call RunallMacros
End Sub

Option Explicit

Sub Worksheet_SelectionChange(ByVal target As Range)

    Dim C As Range

    For Each C In Sheets("Sheet2").Range("Z501")
        If Selection.Count = 1 Then
            If Not Intersect(target, Range("a501")) Is Nothing Then
                Carton = InputBox("Enter Carton Quantity")
                Range("Y501").value = Carton
                If C.value > 0 Then
                    Cubic = InputBox("Enter Cubic")
                    Range("Z501").value = Cubic
                End If
            End If
        End If
    Next
End Sub

尝试将
Carton
输入框限制为仅限数字(请参阅限制代码列表),然后选中
Carton
而不是
C.Value

Dim Carton As Integer
Carton = Application.InputBox("Enter Carton Quantity", Type:=1)
Range("Y501").Value = Carton
If Carton > 0 Then
    Dim Cubic As Integer
    Cubic = Application.InputBox("Enter Cubic", Type:=1)
    Range("Z501").Value = Cubic
End If

不可能使用
inputbox
userform
将是答案。我已经更新并检查了我的答案,以确保它能按您的需要工作,并且看起来它能完成任务。