Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default 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



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alpha with numeric and numeric only numbers in a column rciolkosz Excel Discussion (Misc queries) 6 September 18th 09 09:31 PM
If statement for alpha numeric combo AND numeric only Jdude Excel Discussion (Misc queries) 4 July 13th 09 06:14 AM
Alphanumeric Sorting - numeric alpha numeric Mike Excel Worksheet Functions 2 September 15th 08 10:12 PM
only extract numeric value from alpha numeric cell Fam via OfficeKB.com Excel Discussion (Misc queries) 5 April 26th 06 06:49 PM
The colums changed from alpha to numeric how do you make it alpha worldmade Excel Discussion (Misc queries) 2 May 26th 05 03:44 PM


All times are GMT +1. The time now is 06:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"