I'm struggling with an annoyning possibility, that users can insert decimal/fraction values although only whole numbers should be allowed. I've tried to use KeyAscii (48-57) to check if the users enter numbers. However, I cannot get it to work and neither with some other functions. The user should not be able to insert anything else than numeric values (from 0 to 9 and up to 99). This applies to "rowNum" in my attached code. I have everyhting else in control but I can't get my VBA to work for decimal/fraction values inserted by users after pressing the CommandButton_Click(). I've tried now for many hours to find a solution without success. All help appreciated!
Private Sub CommandButton1_Click()
Dim rowNum As Variant
Dim x As Variant
On Error Resume Next
rowNum = Application.InputBox(Prompt:="Please enter the row from where you want to add new empty rows downwards:", _
Title:="Need to add new empty rows?", Type:=1)
If (VarType(rowNum) = vbBoolean) And (rowNum = False) Then
MsgBox "You canceled the event!", vbExclamation, "No Input!"
ElseIf rowNum = 0 Then
MsgBox "Smallest allowed row number is 7!", vbExclamation, "Invalid Input!"
ElseIf rowNum < 0 Then
MsgBox "Negative values are not allowed!", vbExclamation, "Invalid Input!"
ElseIf rowNum < 7 Then
MsgBox "Smallest allowed row number is 7!!", vbExclamation, "Invalid Input!"
ElseIf rowNum > 99 Then
MsgBox "Highest allowed row number is 99!", vbExclamation, "Invalid Input!"
End If
If rowNum < 7 Or rowNum > 99 Then End
x = Application.InputBox(Prompt:="Please insert the amount of empty rows that you need:", _
Title:="Amount of new rows?", Type:=1)
If (VarType(x) = vbBoolean) And (x = False) Then
MsgBox "You canceled the event!", vbExclamation, "No Input!"
ElseIf x = 0 Then
MsgBox "Smallest amount of new rows is 2!", vbExclamation, "Invalid Input!"
ElseIf x < 2 Then
MsgBox "Smallest amount of new rows is 2!", vbExclamation, "Invalid Input!"
ElseIf x > 10 Then
MsgBox "Highest amount of new rows is 10!", vbExclamation, "Invalid Input!"
End If
If x < 2 Or x > 10 Then End
Rows(rowNum & ":" & rowNum + x - 1).EntireRow.Insert Shift:=xlDown
End Sub
isnumericcan check for numeric values?