0
votes

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.

2
Please describe exactly what you want to test for, what's valid, what's not and why.Alex K.
first name(fname) must contain only aplhabets if not i am priniting cell address which are having wrong dataRajani Rampelli
So anything that's not comprised solely of A-Z/a-z is invalid?Alex K.

2 Answers

0
votes

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
0
votes

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.