Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Extracting a string out of another string

In the following example:

Responsibility: Name1 / Name2 / Name3

How would I extract out Name1 in a macro and put it an an adjacent cell?

Thank you,

Steven
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Extracting a string out of another string

On 13 May, 23:27, Steven wrote:
In the following example:

Responsibility: Name1 / Name2 / Name3

How would I extract out Name1 in a macro and put it an an adjacent cell?

Thank you,

Steven


How about this

Sub extract_first_name()
' where the cell A1 contains "name1/name2/name3"
Dim sResponsibility As String
Dim sFirstName As String
sResponsibility = Cells(1, 1)
sFirstName = Left(sResponsibility, InStr(1, sResponsibility, "/") - 1)
Cells(1, 2) = sFirstName
End Sub

Or if you have a whole column of cells containing multiple names
then ....
Sub extract_first_name_colum()
Dim sResponsibility As String
Dim sFirstName As String
Dim myRow As Integer
myRow = 1

Do Until Cells(myRow, 1) = ""
sResponsibility = Cells(myRow, 1)
sFirstName = Left(sResponsibility, InStr(1, sResponsibility, "/") -
1)
Cells(myRow, 2) = sFirstName
myRow = myRow + 1
Loop
End Sub

Cath
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Extracting a string out of another string

Without any other instruction from you, I'll simply assume that text is in
the ActiveCell. Put this code in your macro...

With ActiveCell
.Offset(0, 1).Value = Trim(Split(Split(.Value, ":")(1), "/")(0))
End With

Rick


"Steven" wrote in message
...
In the following example:

Responsibility: Name1 / Name2 / Name3

How would I extract out Name1 in a macro and put it an an adjacent
cell?

Thank you,

Steven


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Extracting a string out of another string


That is very nice. Thank you.

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
Extracting dates from a String Raj[_2_] Excel Worksheet Functions 7 October 8th 09 01:05 AM
Extracting h:mm:ss from text string Micki Excel Worksheet Functions 19 January 26th 09 05:26 PM
Extracting from string Phil Trumpy Excel Programming 8 March 19th 08 06:04 PM
Extracting string within a string ashg657 Excel Worksheet Functions 5 February 7th 08 10:43 PM
Extracting a string Peter Rooney Excel Discussion (Misc queries) 5 June 20th 06 06:34 PM


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