0

Very newbie question, but I just can't seem to get it to work. Upon selection of cell ("A501") I want to prompt the user to enter a number. I then want to enter that user-input number into cell ("Y501"). After that number has been provided I want a second input box ("Enter Cubic:") to appear, whose value would be automatically placed in cell ("Z501").This is the code that I have on my sheet2, which currently doesn't work

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
2
  • 1
    not possible using inputbox, userform would be the answer
    – Rosetta
    Apr 8, 2016 at 16:38
  • I've updated & checked my answer to make sure it works as you need it to and it appears it does the job. Apr 18, 2016 at 19:27

1 Answer 1

0

Try restricting the Carton InputBox to numbers only (see msdn documentation for list of restriction codes), then check Carton instead of 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.