Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 64
Default Extract first word for a highlighted selection (non contiguoes)

On Dec 3, 1:36 pm, Mike H wrote:
Hi,

Try this

Sub test()
On Error Resume Next
For Each sen In Selection
sen.Value = Left(sen.Value, InStr(1, sen.Value, " ") - 1)
Next
End Sub

Mike

"al" wrote:
Can someone modify the macro below so that it works on a selection of
cells or give me an alternate macro.Thxs


Sub test()
Dim space As Integer, sen As String Dim fword As String
sen = ActiveCell.Value
space = InStr(1, sen, " ")
fword = Left(sen, space - 1)
ActiveCell.Value = fword
End Sub


Hi mike,
it's fine but a text like "0234 mike" gives 234 instead of 0234 - can
you help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Extract first word for a highlighted selection (non contiguoes

Try this

Sub test()
On Error Resume Next
For Each sen In Selection
With sen
.NumberFormat = "@"
.Value = Left(sen.Value, InStr(1, sen.Value, " ") - 1)
End With
Next
End Sub

Mike

"al" wrote:

On Dec 3, 1:36 pm, Mike H wrote:
Hi,

Try this

Sub test()
On Error Resume Next
For Each sen In Selection
sen.Value = Left(sen.Value, InStr(1, sen.Value, " ") - 1)
Next
End Sub

Mike

"al" wrote:
Can someone modify the macro below so that it works on a selection of
cells or give me an alternate macro.Thxs


Sub test()
Dim space As Integer, sen As String Dim fword As String
sen = ActiveCell.Value
space = InStr(1, sen, " ")
fword = Left(sen, space - 1)
ActiveCell.Value = fword
End Sub


Hi mike,
it's fine but a text like "0234 mike" gives 234 instead of 0234 - can
you help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Extract first word for a highlighted selection (non contiguoes

Hi,

I should have mentioned you may now get a small error warning triangle in
cells with leading zeroes warning of numbers stored as text. If you want to
get rid of it:-

Tools|Options - Error checking and un-check 'numbers stored as text'.

Mike

"Mike H" wrote:

Try this

Sub test()
On Error Resume Next
For Each sen In Selection
With sen
.NumberFormat = "@"
.Value = Left(sen.Value, InStr(1, sen.Value, " ") - 1)
End With
Next
End Sub

Mike

"al" wrote:

On Dec 3, 1:36 pm, Mike H wrote:
Hi,

Try this

Sub test()
On Error Resume Next
For Each sen In Selection
sen.Value = Left(sen.Value, InStr(1, sen.Value, " ") - 1)
Next
End Sub

Mike

"al" wrote:
Can someone modify the macro below so that it works on a selection of
cells or give me an alternate macro.Thxs

Sub test()
Dim space As Integer, sen As String Dim fword As String
sen = ActiveCell.Value
space = InStr(1, sen, " ")
fword = Left(sen, space - 1)
ActiveCell.Value = fword
End Sub


Hi mike,
it's fine but a text like "0234 mike" gives 234 instead of 0234 - can
you help

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Extract first word for a highlighted selection (non contiguoes)

Hi
Format your selection as text first, not general.
regards
Paul

On Dec 3, 10:10*am, al wrote:
On Dec 3, 1:36 pm, Mike H wrote:





Hi,


Try this


Sub test()
On Error Resume Next
For Each sen In Selection
* * sen.Value = Left(sen.Value, InStr(1, sen.Value, " ") - 1)
Next
End Sub


Mike


"al" wrote:
Can someone modify the macro below so that it works on a selection of
cells or give me an alternate macro.Thxs


Sub test()
* * Dim space As Integer, sen As String * * * * Dim fword As String
* * sen = ActiveCell.Value
* * space = InStr(1, sen, " ")
* * fword = Left(sen, space - 1)
* * *ActiveCell.Value = fword
End Sub


Hi mike,
it's fine but a text like "0234 mike" gives 234 instead of 0234 - can
you help- Hide quoted text -

- Show quoted text -


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
Can I extract the only second word? Narnimar Excel Discussion (Misc queries) 7 April 4th 23 10:37 AM
extract word before / Wanna Learn Excel Discussion (Misc queries) 3 April 9th 09 04:08 PM
Splitting up one's highlighted selection as if you had used to"control" button for each selection Zarlot Excel Programming 0 May 16th 08 07:31 PM
How to extract right-most word? [email protected] Excel Worksheet Functions 17 July 5th 07 06:43 PM
Tools in excell,word & access not highlighted Patricia Excel Discussion (Misc queries) 0 May 24th 06 12:58 PM


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