Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to Delete Partial Text in a Cell

How do I program a macro to delete the first (or second, or third) text word
in a series of cells?

Specific application is that I want to convert a list of names from:
Joe Smith (in one cell) to
Joe (one cell) and Smith (one cell)

When I use the macro recorder to record my manual actions to delete Joe from
Joe Smith, it records the result of the actions rather than the actions
themselves.

For example, my manual actions to do this we
F2, home, ctrl-R, delete, enter

but the recorded macro is:
ActiveCell.FormulaR1C1 = "Smith"
Range("A5").Select

which when executed on another cell with a different name like Tom Brown,
changes the text to Smith.

This was very easy to do in Lotus 123, but I'm at a loss as to how to do it
in Excel.

Thanks

Oliver
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Macro to Delete Partial Text in a Cell

This is something where the macro recorder won't help you much.
You need something like this:

Sub SplitNames()

Dim i As Long
Dim LR As Long
Dim arr1
Dim arr2
Dim arr3

LR = Cells(65536, 1).End(xlUp).Row

arr1 = Range(Cells(1), Cells(LR, 1))

ReDim arr3(1 To LR, 1 To 2)

For i = 1 To LR
arr2 = Split(arr1(i, 1), " ")
arr3(i, 1) = arr2(0)
arr3(i, 2) = arr2(1)
Next i

Range(Cells(3), Cells(LR, 4)) = arr3

End Sub

The full names should be in column A and the new data will be dumped in
columns C and D.
You may need to add some more code to deal with names that are not like
firstname space surname.


RBS


"Oliver St Quintin" wrote in
message ...
How do I program a macro to delete the first (or second, or third) text
word
in a series of cells?

Specific application is that I want to convert a list of names from:
Joe Smith (in one cell) to
Joe (one cell) and Smith (one cell)

When I use the macro recorder to record my manual actions to delete Joe
from
Joe Smith, it records the result of the actions rather than the actions
themselves.

For example, my manual actions to do this we
F2, home, ctrl-R, delete, enter

but the recorded macro is:
ActiveCell.FormulaR1C1 = "Smith"
Range("A5").Select

which when executed on another cell with a different name like Tom Brown,
changes the text to Smith.

This was very easy to do in Lotus 123, but I'm at a loss as to how to do
it
in Excel.

Thanks

Oliver


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macro to Delete Partial Text in a Cell

Use the =SPLIT() function to separate the words (sort of like Text to columns):

Sub oliver()
v = ""
For Each r In Selection
s = Split(r.Value, " ")
If UBound(s) 0 Then
r.Value = s(0)
r.Offset(0, 1).Value = s(1)
End If
Next
End Sub
--
Gary''s Student - gsnu200728


"Oliver St Quintin" wrote:

How do I program a macro to delete the first (or second, or third) text word
in a series of cells?

Specific application is that I want to convert a list of names from:
Joe Smith (in one cell) to
Joe (one cell) and Smith (one cell)

When I use the macro recorder to record my manual actions to delete Joe from
Joe Smith, it records the result of the actions rather than the actions
themselves.

For example, my manual actions to do this we
F2, home, ctrl-R, delete, enter

but the recorded macro is:
ActiveCell.FormulaR1C1 = "Smith"
Range("A5").Select

which when executed on another cell with a different name like Tom Brown,
changes the text to Smith.

This was very easy to do in Lotus 123, but I'm at a loss as to how to do it
in Excel.

Thanks

Oliver

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
Partial Text Color Change in Cell Rochelles Excel Discussion (Misc queries) 4 December 23rd 08 11:11 PM
Partial Hidden Text in a cell Li Hia Excel Discussion (Misc queries) 2 November 20th 08 01:13 PM
Text Being Seen as Partial Cell Address Mike S. Excel Discussion (Misc queries) 4 March 12th 07 08:12 PM
Vlookup partial text from a single cell Sparky13 Excel Worksheet Functions 4 September 7th 06 01:37 PM
Finding Partial Text in a Cell bob Excel Worksheet Functions 6 December 18th 04 05:03 AM


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