Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default How will I do Excel user-defined function to extract letters from string

How will I extract letters from this string
like... to:

AB-123456-45 AB
BCD-678901-23 BCD
E-23454 E

if I this bottom code extract numbers from a the same string:

Function ExtractNum(rCell As Range)
Dim iCount As Integer, i As Integer
Dim sText As String
Dim lNum As String

sText = rCell

For iCount = Len(sText) To 1 Step -1
If IsNumeric(Mid(sText, iCount, 1)) Then
i = i + 1
lNum = Mid(sText, iCount, 1) & lNum
End If

If i = 1 Then lNum = CInt(Mid(lNum, 1, 1))
Next iCount

ExtractNum = CLng(lNum)
End Function


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default How will I do Excel user-defined function to extract letters from string

Try the following macro

'------------------------------------------------------
Function ExtractNum(rCell As Range
Dim tmp
If Len(rCell.Value) 0 The
For tmp = 1 To Len(rCell.Value
Select Case Asc(Mid(rCell.Value, tmp, 1)
Case 97 To 122, 65 To 9
ExtractNum = ExtractNum & Mid(rCell.Value, tmp, 1
End Selec
Nex
End I
End Functio
'------------------------------------------------------

Regards
Edwin Ta

http://www.vonixx.co


----- Wavit11 wrote: ----

How will I extract letters from this strin
like... to

AB-123456-45 A
BCD-678901-23 BC
E-23454

if I this bottom code extract numbers from a the same string

Function ExtractNum(rCell As Range
Dim iCount As Integer, i As Intege
Dim sText As Strin
Dim lNum As Strin

sText = rCel

For iCount = Len(sText) To 1 Step -
If IsNumeric(Mid(sText, iCount, 1)) The
i = i +
lNum = Mid(sText, iCount, 1) & lNu
End I

If i = 1 Then lNum = CInt(Mid(lNum, 1, 1)
Next iCoun

ExtractNum = CLng(lNum
End Functio



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
User Defined Function is not working for me in Excel 2007 Abdi Excel Discussion (Misc queries) 1 November 18th 08 10:50 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
How can I create a user defined function in excel? Martinj Excel Discussion (Misc queries) 4 August 20th 05 06:11 PM
How to create User Defined function in Excel Johnny Ko Excel Programming 2 December 5th 03 09:09 AM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


All times are GMT +1. The time now is 02:47 PM.

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

About Us

"It's about Microsoft Excel"