Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Extract Certain character from string

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.
Thanks.

1164NB1

How do I extract the "NB" together?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Extract Certain character from string

mid("1164NB1", 5, 2) has a value of "NB"

"Kou Vang" wrote in message
...
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.
Thanks.

1164NB1

How do I extract the "NB" together?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Extract Certain character from string

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Extract Certain character from 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

--
Gary''s Student


"Kou Vang" wrote:

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.
Thanks.

1164NB1

How do I extract the "NB" together?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Extract Certain character from string


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


--
firefytr


------------------------------------------------------------------------
firefytr's Profile: http://www.excelforum.com/member.php...fo&userid=6640
View this thread: http://www.excelforum.com/showthread...hreadid=504974



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Extract Certain character from string

On Wed, 25 Jan 2006 08:53:12 -0800, "Kou Vang"
wrote:

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.
Thanks.

1164NB1

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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Extract Certain character from string

Thanks!

"Cliff Carson" wrote:

mid("1164NB1", 5, 2) has a value of "NB"

"Kou Vang" wrote in message
...
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.
Thanks.

1164NB1

How do I extract the "NB" together?




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Extract Certain character from string

Ron

What a great little function,
I've never come accross that one.

somethinglikeant

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Extract Certain character from string

Oops, thanks Cliff - I was off by one

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Extract Certain character from string

On 25 Jan 2006 10:40:54 -0800, "somethinglikeant" wrote:

Ron

What a great little function,
I've never come accross that one.

somethinglikeant


It has many uses.


--ron
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
How to extract a character from a string then VLOOKUP a table? nginhong Excel Worksheet Functions 7 June 1st 09 10:14 PM
Extract one character Carl Excel Worksheet Functions 4 April 7th 09 04:59 PM
Extract a text string based on character kgiraffa Excel Worksheet Functions 5 March 14th 08 12:54 AM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
Function to return Character Position of Xth character within a string Andibevan[_2_] Excel Programming 4 June 9th 05 03:24 PM


All times are GMT +1. The time now is 01:01 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"