View Full Version : Solved: Checking to see if a cell contains a Number or Letter
Saladsamurai
08-25-2009, 06:22 AM
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!
MaximS
08-25-2009, 07:01 AM
try that:
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
mdmackillop
08-25-2009, 07:27 AM
Couldn't get that to work. My adaption of Maxim's code.
Try
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
MaximS
08-25-2009, 07:30 AM
ehh my mistake double ASC()
Saladsamurai
08-25-2009, 09:57 AM
Great!! Thanks guys! :hi:
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.