简体   繁体   中英

Check cell in excel which should accept only text

如果((Asc(ActiveCell)> 65和Asc(ActiveCell)<95)或(Asc(ActiveCell)> 97和Asc(ActiveCell)<122))然后'If Application.WorksheetFunction.IsText(ActiveCell)然后'If(( Asc(ActiveCell)<65和Asc(ActiveCell))> 90或(Asc(ActiveCell)<97和Asc(ActiveCell)> 122))然后其他FnameTextOnly.Add ActiveCell.Address(False,False)如果ActiveCell.Offset( 1,0).Select End如果单元格的值例如:12as,@#$%,1234时此代码正常工作,但是如果我输入数据例如:asd34,则它不应接受,但应接受,因为名称以文本。

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM