EXCEL VBA : How to validate value with isString or isNumeric?

后端 未结 1 1149
攒了一身酷
攒了一身酷 2021-01-15 23:16

Here is my code below:

Dim m As String, n As Long

n = InputBox(\"Enter sales amount: \")

If n < 500 Or n > 5000 Then
ActiveCell.Value = n
ActiveCell.         


        
相关标签:
1条回答
  • Code:

    Dim m As String, n As String, sales as long
    TryAgain:
    
    n = InputBox("Enter sales amount: ")
    
    If Not IsNumeric(n) Then
        MsgBox "Entry should be a number!"
        GoTo TryAgain
    End If
    
    sales = CLng(n)
    
    If sales < 500 Or sales > 5000 Then
    ActiveCell.Value = sales
    ActiveCell.Interior.Color = RGB(255, 0, 0)
    m = InputBox("Reason why increase/decrease? ")
    ActiveCell.Offset(0, 1).Value = m
    ActiveCell.Offset(1, 0).Select
    
    Else
    ActiveCell.Value = sales
    ActiveCell.Offset(1, 0).Select
    End If
    
    0 讨论(0)
提交回复
热议问题