0
votes

I have some code that works. But i need extra safety that data could not be mixed up. I will put a part of code below and add one comment what i needed.

I need to check if myValue that i entered in InputBox is in this format (## - ## - ##) (#=any number) if not do not enter value in cell but repeat the step until myValue will be in correct format. And if myValue is empty (if i press Cancel in InputBox Exit the Sub)

Sub veikia()


     myValue = InputBox("Nuskenuokite Pakavimo data")
     If myValue > 0 Then
Range("A2").Value = myValue
          End If

Application.Wait (Now + TimeValue("00:00:01"))
               '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
myValue = InputBox("Nusiskenuokite savo paþymëjimà")
If myValue > 0 Then
Range("C2").Value = myValue
    End If  
End Sub

Thanks for help

1

1 Answers

1
votes

The task is easy with Like operator.

Option Explicit

Sub veikia()
Dim myValue As String

Do While True
    myValue = InputBox("Nuskenuokite Pakavimo data")
    If myValue = "" Then
        'if cancel is  pressed exit sub
        Exit Sub
    End If
    If myValue Like "[0-9][0-9]-[0-9][0-9]-[0-9][0-9]" Then
        'if the format is correct then exit loop
        Exit Do
    End If
Loop
'rest of your program
End Sub