非常新手的问题,但我似乎无法让它发挥作用。选择单元格(“A501”)后,我想提示用户输入一个数字。然后,我想将该用户输入的数字输入单元格(“Y501”)。在提供了这个数字后,我想要第二个输入框(“Enter Cubic:”)出现,其值将自动放入单元格(“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
答案 0 :(得分:0)
尝试将Carton
InputBox限制为仅限数字(有关限制代码列表,请参阅msdn documentation),然后选中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