Rajani Rampelli
Rajani Rampelli

Reputation: 179

Check cell in excel which should accept only text

If ((Asc(ActiveCell) > 65 And Asc(ActiveCell) < 95) Or (Asc(ActiveCell) > 97 And Asc(ActiveCell) < 122)) Then 'If Application.WorksheetFunction.IsText(ActiveCell) Then 'If ((Asc(ActiveCell) < 65 And Asc(ActiveCell)) > 90 Or (Asc(ActiveCell) < 97 And Asc(ActiveCell) > 122)) Then Else FnameTextOnly.Add ActiveCell.Address(False, False) End If ActiveCell.Offset(1, 0).Select End If this is code is working properly when the value of cell e.g:12as,@#$%,1234 but if i enter data e.g:asd34 then it should not accept but its accepting because the name starts with text.

Upvotes: 0

Views: 443

Answers (2)

jmdr4
jmdr4

Reputation: 16

Try adding an If statement for ISTEXT (cell reference) to your routine. In this way, ISTEXT (asd34) = False. After qualifying true or false branch accordingly.

Upvotes: 0

Gary&#39;s Student
Gary&#39;s Student

Reputation: 96771

Here is one way to test the ActiveCell

Sub CellText()
    Dim CH As String, v As String
    v = ActiveCell.Text
    For i = 1 To Len(v)
        CH = Mid(v, i, 1)
        If CH Like "[a-zA-Z]" Then
        Else
            MsgBox v & " is not valid"
            Exit Sub
        End If
    Next i
MsgBox v & " is valid"
End Sub

Upvotes: 0

Related Questions