Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jip jip is offline
external usenet poster
 
Posts: 8
Default Text manipulation with Visual Basic

Platform: Windows 2000/Excel 2000


Is there anybody out here who is able to help me solving following
Excel-case, I am a novice using VB therefore I hope you are a little passion
with me:

I have an Excel-file consists of approximately 56000 rows and 10 columns,
one of these columns (lets say column E) contain a description of characters
from 0 to 80.

I need Visual-basic to go through each cell in column E and divide the text
into two "lines" first "line" can maximum consist of 40 characters the
second "line" has no maximum. My problem is that the text often will be
divided in middle of a word that I do not want.
Therefore I imagine the program first check on character 40 if it is a
"space" or not. If it is a space nothing has to be done opposite the program
must go back through the text from character 40 until it meet a space.
Afterwards it shall put in "spaces" from the found space up to characters
40.

That is all what I need.

JIP



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Text manipulation with Visual Basic

Sub AABB()
Dim rng As Range, cell As Range
Dim sStr As String, sSTr1 As String
Dim i As Long
Set rng = Range(Cells(2, 5), Cells(Rows.Count, 5).End(xlUp))

For Each cell In rng
' remove trim if you don't want leading and
' trailing spaces removed
sStr = Trim(cell.Value)
If Len(sStr) 40 Then
sSTr1 = Left(sStr, 40)
i = 40
Do While Mid(sSTr1, i, 1) < " " And i 0
i = i - 1
Loop
If i < 2 Then
cell.Interior.ColorIndex = 3
Else
sStr = Left(sStr, i - 1) & vbLf & Right(sStr, Len(sStr) - i)
cell.Value = sStr
End If
End If
Next
End Sub

Test on a copy of your workbook/data. You will need to format the column to
wordwrap.

--
Regards,
Tom Ogilvy


"jip" wrote in message
...
Platform: Windows 2000/Excel 2000


Is there anybody out here who is able to help me solving following
Excel-case, I am a novice using VB therefore I hope you are a little

passion
with me:

I have an Excel-file consists of approximately 56000 rows and 10 columns,
one of these columns (lets say column E) contain a description of

characters
from 0 to 80.

I need Visual-basic to go through each cell in column E and divide the

text
into two "lines" first "line" can maximum consist of 40 characters the
second "line" has no maximum. My problem is that the text often will be
divided in middle of a word that I do not want.
Therefore I imagine the program first check on character 40 if it is a
"space" or not. If it is a space nothing has to be done opposite the

program
must go back through the text from character 40 until it meet a space.
Afterwards it shall put in "spaces" from the found space up to characters
40.

That is all what I need.

JIP





  #3   Report Post  
Posted to microsoft.public.excel.programming
jip jip is offline
external usenet poster
 
Posts: 8
Default Text manipulation with Visual Basic

Hi Tom,
Thank you for the help I now just need to test it. When you mention wordwrap
do you meant by that I have to change the column to text in the excel file
before I do the program manipulation, or...? Sorry, but as I wrote I am
novice using VB.
JIP
"Tom Ogilvy" skrev i en meddelelse
...
Sub AABB()
Dim rng As Range, cell As Range
Dim sStr As String, sSTr1 As String
Dim i As Long
Set rng = Range(Cells(2, 5), Cells(Rows.Count, 5).End(xlUp))

For Each cell In rng
' remove trim if you don't want leading and
' trailing spaces removed
sStr = Trim(cell.Value)
If Len(sStr) 40 Then
sSTr1 = Left(sStr, 40)
i = 40
Do While Mid(sSTr1, i, 1) < " " And i 0
i = i - 1
Loop
If i < 2 Then
cell.Interior.ColorIndex = 3
Else
sStr = Left(sStr, i - 1) & vbLf & Right(sStr, Len(sStr) - i)
cell.Value = sStr
End If
End If
Next
End Sub

Test on a copy of your workbook/data. You will need to format the column

to
wordwrap.

--
Regards,
Tom Ogilvy


"jip" wrote in message
...
Platform: Windows 2000/Excel 2000


Is there anybody out here who is able to help me solving following
Excel-case, I am a novice using VB therefore I hope you are a little

passion
with me:

I have an Excel-file consists of approximately 56000 rows and 10

columns,
one of these columns (lets say column E) contain a description of

characters
from 0 to 80.

I need Visual-basic to go through each cell in column E and divide the

text
into two "lines" first "line" can maximum consist of 40 characters the
second "line" has no maximum. My problem is that the text often will be
divided in middle of a word that I do not want.
Therefore I imagine the program first check on character 40 if it is a
"space" or not. If it is a space nothing has to be done opposite the

program
must go back through the text from character 40 until it meet a space.
Afterwards it shall put in "spaces" from the found space up to

characters
40.

That is all what I need.

JIP







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Text manipulation with Visual Basic

I would see no reason to do anything but run the macro on a copy of your
workbook.

if you see the text as a single line with a square box shown in the text,
then you need to select the column and do

Format=Cells=Alignment tab and select Wrap text. Make the column width
at least 40 characters wide.

this part has nothing to do with VBA.

--
Regards,
Tom Ogilvy




"jip" wrote in message
...
Hi Tom,
Thank you for the help I now just need to test it. When you mention

wordwrap
do you meant by that I have to change the column to text in the excel file
before I do the program manipulation, or...? Sorry, but as I wrote I am
novice using VB.
JIP
"Tom Ogilvy" skrev i en meddelelse
...
Sub AABB()
Dim rng As Range, cell As Range
Dim sStr As String, sSTr1 As String
Dim i As Long
Set rng = Range(Cells(2, 5), Cells(Rows.Count, 5).End(xlUp))

For Each cell In rng
' remove trim if you don't want leading and
' trailing spaces removed
sStr = Trim(cell.Value)
If Len(sStr) 40 Then
sSTr1 = Left(sStr, 40)
i = 40
Do While Mid(sSTr1, i, 1) < " " And i 0
i = i - 1
Loop
If i < 2 Then
cell.Interior.ColorIndex = 3
Else
sStr = Left(sStr, i - 1) & vbLf & Right(sStr, Len(sStr) - i)
cell.Value = sStr
End If
End If
Next
End Sub

Test on a copy of your workbook/data. You will need to format the

column
to
wordwrap.

--
Regards,
Tom Ogilvy


"jip" wrote in message
...
Platform: Windows 2000/Excel 2000


Is there anybody out here who is able to help me solving following
Excel-case, I am a novice using VB therefore I hope you are a little

passion
with me:

I have an Excel-file consists of approximately 56000 rows and 10

columns,
one of these columns (lets say column E) contain a description of

characters
from 0 to 80.

I need Visual-basic to go through each cell in column E and divide the

text
into two "lines" first "line" can maximum consist of 40 characters

the
second "line" has no maximum. My problem is that the text often will

be
divided in middle of a word that I do not want.
Therefore I imagine the program first check on character 40 if it is a
"space" or not. If it is a space nothing has to be done opposite the

program
must go back through the text from character 40 until it meet a space.
Afterwards it shall put in "spaces" from the found space up to

characters
40.

That is all what I need.

JIP









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
Currency format in visual basic text box James Millsted Excel Discussion (Misc queries) 2 June 15th 07 11:47 AM
Visual Basic Text Functions Moiz Excel Programming 3 August 18th 04 02:16 PM
Set cell text direction (degrees property?) via visual basic James[_24_] Excel Programming 2 June 23rd 04 01:03 PM
Converting text to pdf file using Visual Basic nitin khabia Excel Programming 1 September 12th 03 02:10 AM
Visual basic to step through range and store a value based on text attribute value. Bob Kilmer Excel Programming 0 August 7th 03 09:46 PM


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