I have this procedure to check the input of a cell (and it is working as expected):
' Check for validation in column P
If Not Intersect(Target, Me.Columns("P")) Is Nothing Then
' Loop through each changed cell in the target range
For Each cell In Target
' Check if the cell value matches the specified pattern
cellValue = cell.value
' Check if the value starts with 2 numbers representing the last 2 digits of the current or previous year followed by a dash
' and has a total length of 9 characters
Do While Not IsValidYearFormat(cellValue) Or Len(cellValue) <> 9 Or Not AreLastSixDigitsNumeric(Right(cellValue, 6))
' Prompt the user to enter a new value
newValue = InputBox("Ongeldige notatie BPS mutatienummer in cel " & cell.address & " in kolom P. De waarde moet beginnen met 2 cijfers die de laatste 2 cijfers van het huidige of vorige jaar vertegenwoordigen, gevolgd door een streepje en moet in totaal 9 karakters lang zijn." & vbCrLf & "Voer een nieuwe waarde in die aan de criteria voldoet:", "Nieuwe waarde invoeren", cell.value)
If newValue = "" Then Exit Sub ' Exit if the user cancels the input box
' Validate the new value
If Not IsValidYearFormat(CStr(newValue)) Or Len(newValue) <> 9 Or Not AreLastSixDigitsNumeric(Right(newValue, 6)) Then
' Display error message if the new value is invalid
MsgBox "Ongeldige notatie. De waarde moet beginnen met 2 cijfers die de laatste 2 cijfers van het huidige of vorige jaar vertegenwoordigen, gevolgd door een streepje en moet in totaal 9 karakters lang zijn. Bovendien moeten de laatste 6 karakters cijfers zijn.", vbExclamation, "Formaatcontrole"
Else
' Replace the original value with the new valid value
cell.value = newValue
' Exit the loop if the value is valid
Exit Do
End If
Loop
Next cell
End If
I used this exact procedure and changed it a bit, but now the ‘isnumeric’ part is not working anymore:
' Check for validation in column O
If Not Intersect(Target, Me.Columns("O")) Is Nothing Then
' Loop through each changed cell in the target range
For Each cell In Target
' Check if the cell value matches the specified pattern
cellValue = cell.value
' Check if the value is all-numeric and is 7 characters long
Do While Len(cellValue) <> 7 Or Not AreLastSixDigitsNumeric(cellValue)
' Prompt the user to enter a new value
newValue = InputBox("Ongeldige notatie VBS mutatienummer in cel " & cell.address & " in kolom O. De waarde bestaan uit cijfers en 7 cijfers lang zijn." & vbCrLf & "Voer een nieuwe waarde in die aan de criteria voldoet:", "Nieuwe waarde invoeren", cell.value)
If newValue = "" Then Exit Sub ' Exit if the user cancels the input box
' Validate the new value
If Len(newValue) <> 7 Or Not AreLastSixDigitsNumeric(cellValue) Then
' Display error message if the new value is invalid
MsgBox "Ongeldige notatie. De waarde moet beginnen met 2 cijfers die de laatste 2 cijfers van het huidige of vorige jaar vertegenwoordigen, gevolgd door een streepje en moet in totaal 9 karakters lang zijn. Bovendien moeten de laatste 6 karakters cijfers zijn.", vbExclamation, "Formaatcontrole"
Else
' Replace the original value with the new valid value
cell.value = newValue
' Exit the loop if the value is valid
Exit Do
End If
Loop
Next cell
End If
With this procedure, it does not matter what I enter (123456 or abcdef or 123abc etc.), every value is not accepted as numeric (and the popup with the error message returns).
Is there any simple explanation why the IsNumeric function does not work?
4