MsgBox if entered value in the cell is text

54 Views Asked by At

Dears,

Iam trying to create a Data validation in VBA. Imagine I have a range of cells A1:A10 and I want a MsgBox to pop up if user enter text in one of the cells.

Iam trying below but does not work.

Sub test()

Dim rcell As Range
Set rcell = Range("A1:A10")

If IsEmpty(rcell) Or IsNumeric(rcell.Value) Then
Else
MsgBox "Error"
End If

End Sub

1

There are 1 best solutions below

0
MGonet On

In the sheet module put the code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
    Set Target = Intersect(Target, Range("A1:A10"))
    If Target Is Nothing Then Exit Sub
    If Application.CountIf(Target, "*") Then _
        MsgBox "Error"
End Sub

When you type or paste text into any of the cells A1:A10 an error message appears.