VBA, USERFORM, inputbox not accepting "2" as a value

Sandcastor

Board Regular
Joined
May 14, 2012
Messages
97
I've built a custom print box userform, with the help of quite a few of the gurus here.
Print_Box.png

I'm using Von Pookie's code to parse the checkboxes in the form, and iterate an input box so the user can type how many copies of each checked form to print. I'm currently working on the "Sample Labels" button, because it is the easiest, and will add other buttons from there. (Checkboxes 4-12 are disabled for debugging)

The problem I am finding is that since using a For-Loop to fill the Variables, the inputboxes will not accept the number 2 as a response. Every other value works. And 2 is the most likely value to be entered in the box. Full script follows, probem area highlighted.

Code:
Private Sub PrintSampleLabels_Click()
Dim CBox As Control
Dim i As Long
Dim P As Variant
Dim N(12) As Variant
Dim NS As Variant
Dim answer
Dim Message, Title, Default
    Title = "Print Copies"                                              'Set title.
    Default = "2"                                                       'Set default.

NS = InputBox("How many sheets of labels for the injection well?", "Print Copies")
If NS = vbCancel Then NS = 0

[COLOR=#800000]For i = 1 To 12
        On Error Resume Next
        Set CBox = Me.Controls("Offset" & i)
                If CBox.Value = False Then
                    P = 0
                    GoTo Nextbox
                    End If
                P = InputBox("How many sheets of labels for offset well #" & i & "?", "Print Copies")
                If P = vbCancel Then P = 0
            N(i) = CInt(P)
Nextbox:
    Next i
[/COLOR]    
                
If WorksheetFunction.Sum(N) + NS = 0 Then GoTo TheEnd
answer = MsgBox("Load " & WorksheetFunction.Sum(N) + NS & " sheets of blank Sample Labels into the printer.", vbOKCancel, "LABELS!")
If answer = vbCancel Then Exit Sub ' the macro ends if the user selects the CANCEL-button
Application.ScreenUpdating = False
If NS = 0 Then GoTo Skip
    Sheets("SCHEM Sample Labels").PrintOut copies:=NS, Collate:=True, Preview:=False 'ActivePrinter:=
Skip:
    For i = 1 To 12
        Set CBox = Me.Controls("Offset" & i)
        If CBox.Value = True And N(i) > 0 Then Sheets("SCHEM OFFSET " & i & " Labels").PrintOut copies:=N(i), Collate:=True, Preview:=False 'ActivePrinter:=
    Next i
    
    
TheEnd:
Application.ScreenUpdating = True
End Sub

I have tweaked the code about six times, modified the error handlers, adjusted variable placement, and tried Integer, Long, and Variant variable types, always with the same result.
Help, please?
 
Last edited:
I was beginning to suspect, but was more focused on the fix than the "why".

But I love knowing the "why, Thanks!
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top