Share via

Run-Time error '381' but not really sure what the problem is

Anonymous
2012-08-14T21:08:40+00:00

Okay I have a procedure that runs fine until I get to the the third and last item in my listbox the procedure is below.  This procedure goes through every item (which is in column 1) in my list box and uses an Input box to request a quantity for each then places the number in the 2nd column on the same row as the item.  For some reason this has worked fine until I get to the third item in the list when I input the number 940 I get stuck in a loop with my error handler, the error handler is there to prevent the end user form putting anything except numbers in the input box.

I get stuck in a loop with the Msgbox "Please Enter a Number"

Sub runlist()

Dim part As String

Dim qty As Long

Dim i As Long

For i = 0 To ListBox1.ListCount - 1

part = ListBox1.list(i, 1)

qty:

On Error GoTo ErrHandler:

qty = InputBox("Enter Qty for " & part & ":", "Qty Enter")

GoTo last:

ErrHandler:

Err.Clear

If qty = 0 Then

Exit Sub

End If

MsgBox ("Please Enter A Number")

Resume

GoTo qty:

last:

With ListBox1

.list(i, 2) = qty

End With

Next i

Call qtyupdate

End Sub

After hitting Ctrl/Break I went into debug and the line that says "Resume" was highlighted, so I tried deleting that line and clicking play then it stopped on the line

.list(i,2)=qty

where i = 3 and qty=940

The specific error I get after pressing play is "Run-time error '381': Could not set the List property. Invalid property array index."

Please Help

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-08-14T22:42:43+00:00

Without looking at why your code would be bombing you can validate an Applicaiton.InputBox which is different from a regualr inputbox. Check out this link...

http://msdn.microsoft.com/en-us/library/office/aa195768(v=office.11).aspx

You would want

 qty = application.InputBox("Enter Qty for " & part & ":", "Qty Enter", Type:=1)

where 1 specifies numbers only.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-08-15T14:40:13+00:00

    There are left and top arguments...

    Prompt Required String. The message to be displayed in the dialog box. This can be a string, a number, a date, or a Boolean value (Microsoft Excel automatically coerces the value to a String before it's displayed).

    Title Optional Variant. The title for the input box. If this argument is omitted, the default title is "Input."

    Default Optional Variant. Specifies a value that will appear in the text box when the dialog box is initially displayed. If this argument is omitted, the text box is left empty. This value can be a **Range** object.

    Left Optional Variant. Specifies an x position for the dialog box in relation to the upper-left corner of the screen, in points.

    Top Optional Variant. Specifies a y position for the dialog box in relation to the upper-left corner of the screen, in points.

    HelpFile Optional Variant. The name of the Help file for this input box. If the HelpFile and HelpContextID arguments are present, a Help button will appear in the dialog box.

    HelpContextId Optional Variant. The context ID number of the Help topic in HelpFile.

    Type Optional Variant. Specifies the return data type. If this argument is omitted, the dialog box returns text. Can be one or a sum of the following values.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-08-15T13:17:55+00:00

    How do you determine where the applicaiton.inputbox opens on the screen.  In my three monitor setup it opened on a different monitor all three times??

    Was this answer helpful?

    0 comments No comments