ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Statement based on Alpha or Numeric (https://www.excelbanter.com/excel-programming/311153-if-statement-based-alpha-numeric.html)

Ryan

If Statement based on Alpha or Numeric
 
I am trying to do an if statement based on whether a character is numeric or
alpha.

e.g. I have the following spreadsheets:

A
1 01-BHZ
2 01-049

Basically what I am wanting to do is an if statement based on a mid formula.

i.e. if mid(A1,4,1) is numeric then "Numeric", if not "Alpha"

Is there a formula I can use? Is it a public function with a bit of VBA?

Please help

Regards,

Ryan

Tom Ogilvy

If Statement based on Alpha or Numeric
 
=if(iserror(1*mid(A1,4,1)),"Text","Numeric")

--
Regards,
Tom Ogilvy

"Ryan" wrote in message
...
I am trying to do an if statement based on whether a character is numeric

or
alpha.

e.g. I have the following spreadsheets:

A
1 01-BHZ
2 01-049

Basically what I am wanting to do is an if statement based on a mid

formula.

i.e. if mid(A1,4,1) is numeric then "Numeric", if not "Alpha"

Is there a formula I can use? Is it a public function with a bit of VBA?

Please help

Regards,

Ryan




Bernie Deitrick

If Statement based on Alpha or Numeric
 
Ryan,

With a worksheet function:
=IF(ISNUMBER(VALUE(MID(A1,4,1))),"It's a number","It's not a number")

In a macro:

Sub Macro1()
Dim myNum As Integer
On Error GoTo NotNumber
myNum = CInt(Mid(Range("A1").Value, 4, 1))
MsgBox "It's a number"
Exit Sub
NotNumber:
MsgBox "It's not a number"
End Sub

Or

Sub Macro2()
Dim myNum As Integer
myNum = Asc(Mid(Range("A1").Value, 4, 1))
If myNum = Asc("0") And myNum <= Asc("9") Then
MsgBox "It's a number"
Else
MsgBox "It's not a number"
End If
End Sub

HTH,
Bernie
MS Excel MVP

"Ryan" wrote in message
...
I am trying to do an if statement based on whether a character is numeric

or
alpha.

e.g. I have the following spreadsheets:

A
1 01-BHZ
2 01-049

Basically what I am wanting to do is an if statement based on a mid

formula.

i.e. if mid(A1,4,1) is numeric then "Numeric", if not "Alpha"

Is there a formula I can use? Is it a public function with a bit of VBA?

Please help

Regards,

Ryan




Kris

If Statement based on Alpha or Numeric
 
Interesting solution.

I was going to suggest something more like:

=IF(AND(MID(A4,4,1)="0",MID(A4,4,1)
<="9"),"Numeric","Alpha")

Your solution is shorter and has more finesse to it, :)

Sincerely,

Kris

-----Original Message-----
=if(iserror(1*mid(A1,4,1)),"Text","Numeric")

--
Regards,
Tom Ogilvy

"Ryan" wrote in message
news:3170FAEB-42FB-4AD1-AE5B-

...
I am trying to do an if statement based on whether a

character is numeric
or
alpha.

e.g. I have the following spreadsheets:

A
1 01-BHZ
2 01-049

Basically what I am wanting to do is an if statement

based on a mid
formula.

i.e. if mid(A1,4,1) is numeric then "Numeric", if

not "Alpha"

Is there a formula I can use? Is it a public function

with a bit of VBA?

Please help

Regards,

Ryan



.



All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com