Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to find a comma in a string

A1 contains LastName, FirstName
If B1 = mid(A1,1,find(",",A1)-1) then B1 will be = to the LastName.
How can I write a macro that will returen the LastName to whatever the
ActiveCell is?

Chuck L
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to find a comma in a string

ActiveCell.Value = Mid(Range("A1"),1,Instr(Range("A1"),",")-1)

--
Regards,
Tom Ogilvy


"Chuck" wrote in message
...
A1 contains LastName, FirstName
If B1 = mid(A1,1,find(",",A1)-1) then B1 will be = to the LastName.
How can I write a macro that will returen the LastName to whatever the
ActiveCell is?

Chuck L



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro to find a comma in a string


iPos = Instr(1,Range("A1").Value,",")
If iPos 0 Then
Activecell.Value = Right(Range("A1").Value, _
Len(Range("A1").Value) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Chuck" wrote in message
...
A1 contains LastName, FirstName
If B1 = mid(A1,1,find(",",A1)-1) then B1 will be = to the LastName.
How can I write a macro that will returen the LastName to whatever the
ActiveCell is?

Chuck L



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to find a comma in a string

Think you would need LEFT for lastname.

Sub AA()
iPos = InStr(1, Range("A1").Value, ",")
If iPos 0 Then
ActiveCell.Value = Left(Range("A1").Value, _
iPos - 1)
End If

End Sub

--
Regards,
Tom Ogilvy

"Bob Phillips" wrote in message
...

iPos = Instr(1,Range("A1").Value,",")
If iPos 0 Then
Activecell.Value = Right(Range("A1").Value, _
Len(Range("A1").Value) - iPos)
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Chuck" wrote in message
...
A1 contains LastName, FirstName
If B1 = mid(A1,1,find(",",A1)-1) then B1 will be = to the LastName.
How can I write a macro that will returen the LastName to whatever the
ActiveCell is?

Chuck L





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to find a comma in a string

On Tue, 23 Aug 2005 21:44:11 +0100, "Bob Phillips"
wrote:


iPos = Instr(1,Range("A1").Value,",")
If iPos 0 Then
Activecell.Value = Right(Range("A1").Value, _
Len(Range("A1").Value) - iPos)
End If


Slightly different approach. However, *Range* is the magic word.
Thank you.

Chuck


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to find a comma in a string

On Tue, 23 Aug 2005 21:18:41 -0400, "Tom Ogilvy" wrote:

Think you would need LEFT for lastname.

Sub AA()
iPos = InStr(1, Range("A1").Value, ",")
If iPos 0 Then
ActiveCell.Value = Left(Range("A1").Value, _
iPos - 1)
End If

End Sub


I have a number of cell I'm working with and all but this one require the *Mid*
function. I just got carried away with *Mid*. However, I am going to change
this one cell to use *Left*. It is just a cleaner function for this case.

Thank you.

Chuck
--
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to find a comma in a string

On Tue, 23 Aug 2005 16:36:15 -0400, "Tom Ogilvy" wrote:

ActiveCell.Value = Mid(Range("A1"),1,Instr(Range("A1"),",")-1)


*Range* is the magic word. I had the ActiveCell.Value part.
Thank you.

Chiuck
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to find a comma in a string

On Tue, 23 Aug 2005 21:44:11 +0100, "Bob Phillips"
wrote:


iPos = Instr(1,Range("A1").Value,",")
If iPos 0 Then
Activecell.Value = Right(Range("A1").Value, _
Len(Range("A1").Value) - iPos)
End If


A slightly different approach. Hwever, *Range* is still the magic word.

Thank you.

Chuck
--
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Macro to find a comma in a string

On Tue, 23 Aug 2005 16:36:15 -0400, "Tom Ogilvy" wrote:

ActiveCell.Value = Mid(Range("A1"),1,Instr(Range("A1"),",")-1)

*Range* is the magic word.

Thank you

Chuck
--
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
text string separated by comma Atishoo Excel Discussion (Misc queries) 6 February 12th 09 05:19 PM
test text string for a comma (,) JR Hester Excel Discussion (Misc queries) 3 June 24th 08 04:14 AM
Macro to find text string in a column and paste data in another nicolascap Excel Discussion (Misc queries) 8 March 14th 06 03:13 PM
find and remove a string of a cell value with comma as delimiter yefei Excel Discussion (Misc queries) 3 February 28th 06 01:05 PM
Convert comma separated string to DropDown ssuyog Excel Programming 2 November 19th 04 05:49 PM


All times are GMT +1. The time now is 09:13 AM.

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"