mid("1164NB1", 5, 2) has a value of "NB"
> How do you extract a certain character from right to left? This is so
> simple, yet finding any help code takes me to a million other examples.
[quoted text clipped - 3 lines]
>
> How do I extract the "NB" together?
Kou Vang - 25 Jan 2006 17:22 GMT
Thanks!
> mid("1164NB1", 5, 2) has a value of "NB"
>
[quoted text clipped - 5 lines]
> >
> > How do I extract the "NB" together?
Glen - 25 Jan 2006 18:47 GMT
Oops, thanks Cliff - I was off by one
Declare str1 as a string
Set str1 = 1164NB1 as your string value
then use the MID function:
MID(str1,4,2)
This will grab and return the 4th and 5th characters of your string
In the worksheet, pull-down:
Edit > Find and then enter NB, leave the replace field blank and click
replace.
You should see:
11641
In VBA (using the Recorder)
Sub Macro1()
ActiveCell.Replace What:="NB", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Find(What:="NB", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False _
, SearchFormat:=False).Activate
End Sub

Signature
Gary''s Student
> How do you extract a certain character from right to left? This is so
> simple, yet finding any help code takes me to a million other examples.
[quoted text clipped - 3 lines]
>
> How do I extract the "NB" together?
firefytr - 25 Jan 2006 17:11 GMT
Not sure where my post went, but I'll try again.
Besides the Mid function, you could also use RegExp (do a google
search) or a simple loop, such as ..
Code:
--------------------
Option Explicit
Sub TestMePlease()
MsgBox RemoveNumbers("1164NB1")
End Sub
Function RemoveNumbers(strVal As Variant) As String
Dim i As Long, tmp As String
On Error Resume Next
For i = 1 To Len(strVal)
Select Case Asc(UCase(Mid(strVal, i, 1)))
Case 65 To 90
tmp = tmp & Mid(strVal, i, 1)
End Select
Next i
If Len(tmp) > 0 Then
RemoveNumbers = tmp
Else
RemoveNumbers = "No Text"
End If
End Function
--------------------
HTH

Signature
firefytr
>How do you extract a certain character from right to left? This is so
>simple, yet finding any help code takes me to a million other examples.
[quoted text clipped - 3 lines]
>
>How do I extract the "NB" together?
Your question is not clear.
What do you want to do with "extracted" character?
Should your result be 11641 or should your result be NB?
Or something else?
You can certainly remove NB from the string (is that what you mean by extract?)
with the SUBSTITUTE function:
=SUBSTITUTE("1164NB1","NB","")--> "11641"
but I'm thinking you want something more general.
You can substitute cell references for any of the arguments in the SUBSTITUTE
function.
--ron
somethinglikeant - 25 Jan 2006 18:40 GMT
Ron
What a great little function,
I've never come accross that one.
somethinglikeant
Ron Rosenfeld - 25 Jan 2006 19:24 GMT
>Ron
>
>What a great little function,
>I've never come accross that one.
>
>somethinglikeant
It has many uses.
--ron