• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

input box number only

pencari

New Member
hi guys
i am trying to make input box just number only

Code:
Private Sub CommandButton3_Click()
Dim firstnumber As Integer
Dim lastnumber As Integer
Dim i As Integer



On Error GoTo error1


firstnumber = InputBox("Input the first number")
If Not IsNumeric(firstnumber) Then
MsgBox ("Number Only")
Else
lastnumber = InputBox("Masukan No Akhir yang Akan di Print")
If Not IsNumeric(lastnumber) Then
MsgBox ("Number Only")
Else
For i = firstnumber To lastnumber
Workbooks("ASDASD.xlsm").Activate
Worksheets("Sheet1").Range("Q4").Value = i
    Range("B2:N27").PrintOut
    Application.Wait (Now + TimeValue("00:00:10"))
Next i
End If
error1:
  Exit Sub
End Sub

i get an error with if with an end if

can u guys point me what is wrong with the code?

error1 is for detecting when the customer click an cancel so there is no typemissmatch error

thx
 
How many 'If' do You have?
How many 'EndIf' do You have?
>> Where is 1st 'If's 'EndIf'?
Code:
If xx then
    yy
else
    If xxx then
        yyy
    else
        yyyy
    endif
Endif      ' where is this Endif
 
Hi ,

Try this :
Code:
Private Sub CommandButton1_Click()
            Dim firstnumber As Variant, lastnumber As Variant, i As Integer

            On Error GoTo error1

            firstnumber = InputBox("Input the first number")
            If Not IsNumeric(firstnumber) Then
              MsgBox ("Number Only")
            Else
              lastnumber = InputBox("Masukan No Akhir yang Akan di Print")
              If Not IsNumeric(lastnumber) Then
                  MsgBox ("Number Only")
              Else
                  For i = firstnumber To lastnumber
                      Workbooks("ASDASD.xlsm").Activate
                      ActiveWorkbook.Worksheets("Sheet1").Range("Q4").Value = i
                      Range("B2:N27").PrintOut
                      Application.Wait (Now + TimeValue("00:00:10"))
                  Next i
              End If
            End If
error1:
End Sub
Narayan
 
Back
Top