LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
nmp nmp is offline
external usenet poster
 
Posts: 11
Default Pull a set number of characters from a cell without cutting of

OK. I'm not that great at VBA and macros. Any chance you can step me
through exactly what I need to do if my data is in E2 through E1587?

Here is some more detail on what I have: I have 3 fields available for my
description. Description Field 1 needs to be limited to 50 characters.
Anything over 50 characters I want to break on the whole word and put in
Description Field 2 which needs to be limited to 40 characters. There are a
few descriptions that are over 90 characters long, in which case I want to
put anything remaining in Description Field 3. Field 3 needs to be limited
to 40 characters too, but I do not have any descriptions over 130 characters.
Currently the full descriptions are all in column E.

Hope this helps.

Thanks!

"NickHK" wrote:

Possibly:

Public Function TruncateOnWholeWord(SampleText As Variant, Optional
MaxLength As Long = 50) As String

'No problem, just return the input
If Len(SampleText) <= MaxLength Then
TruncateOnWholeWord = SampleText
Exit Function
End If

'If the 51st char is a [SPACE], then we can take the first 50 chars OK
'And other tests for what you consider the End-Of-Word char
If Mid(SampleText, 51, 1) = " " Then
TruncateOnWholeWord = Left(SampleText, 50)
Exit Function
End If

'OK, need to do some work
'Find the first [SPACE] before the 51st char
TruncateOnWholeWord = Left(SampleText, InStrRev(SampleText, " ", 51) - 1)

End Function

Depending on your requirements, you can add Trim to strip spaces

NickHK

"nmp" wrote in message
...
I need to be able to pull a set number of characters from a cell, but I do
not what to cut off a word if that set number ends up in the middle of a

word.

For example I have: 11 x 8-1/2, 80# Patient Education Shell #501324 CREAM

..
By using a LEFT(A2,50) it cuts off the EAM in CREAM. I actually want to

cut
off the whole word and put it in a different cell. Make sense? Is that
possible?

Thanks!






 
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
I need to have a certain number of characters in a cell jerminski73 Excel Discussion (Misc queries) 9 November 11th 08 11:07 AM
cutting characters from a cell LAndersen Excel Worksheet Functions 5 January 6th 07 02:46 AM
Pull whole words from a cell up to a set number of characters. nmp Excel Programming 4 October 12th 06 04:13 AM
How do I pull just the numeric characters in a cell? punter Excel Discussion (Misc queries) 4 August 1st 06 09:49 PM
Number of characters in a cell Braders999 Excel Discussion (Misc queries) 3 July 10th 06 02:39 PM


All times are GMT +1. The time now is 06:59 AM.

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"