-
Solved: Checking to see if a cell contains a Number or Letter
Alrighty-then
Let's say that I want to write, in VBA, a code that will check Cell(i,j)
and if it contains a letter (any letter) it will MsgBox "Letter" and if it contains a Number (any number) it will do nothing.
How do I specify a letter in general? Is there a Chr() code or something?
Thanks!
-
try that:
[vba]
Sub Chr_Check()
Dim x As String
x = Asc(Cells(1, 1).Value)
Select Case Asc(x)
Case 65 To 90
Err = MsgBox(Cells(1, 1).Address & " is a Letter", vbOKOnly, "Letter")
Case 67 To 122
Err = MsgBox(Cells(1, 1).Address & " is a Letter", vbOKOnly, "Letter")
End Select
End Sub
[/vba]
-
Couldn't get that to work. My adaption of Maxim's code.
Try
[VBA]
Option Explicit
Sub Chr_Check()
Dim x As Long
x = Asc(Cells(1, 1).Value)
Select Case x
Case 65 To 90
Err = MsgBox(Cells(1, 1).Address & " is a Letter", vbOKOnly, "Letter")
Case 67 To 122
Err = MsgBox(Cells(1, 1).Address & " is a Letter", vbOKOnly, "Letter")
Case Else
If IsNumeric(Cells(1, 1)) Then
MsgBox "Number"
Else
MsgBox "Symbol"
End If
End Select
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
ehh my mistake double ASC()
-
Great!! Thanks guys!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules