Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Text To Column max 26 characters


With these three examples in a single cell, say A1 & A4 & A7, I have a simple macro to put each char into a individual cell (including spaces).

What I want is a 26 char limit per line, space counts as a char.
In the first line the 26th spot falls in one of the spaces, so a break there is good to put the remaining chars on the next line.

In the second line the 26th char falls between the "YP" so in this case I need to back up to the first available space before "YP" and make the break there.

The third line is less than 26 char so it needs no split, but needs to be included in the final 'each char in an individual cell' caper.

HZG MY AG AGHTO TYMVKTZ. K RHT'M ZGM YIJ; K'A

UYQTZ. XVGT K'A KT PEYTM YP HT HQJKGTRG, HII MVHM

ZGYEZG NQETO

Either of the following capers is fine with me.

1. Run the text to columns code and put the entire line in individual cells (including spaces) then run a "26 char max that does not split a word" code and have the line on two rows now.

2. Split the line as is with a "26 char max that does not split a word" code and then run the text to columns code on those lines to put each char in individual cells.

Finding that proper space to make the line break has me stumped.

Thanks,
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Text To Column max 26 characters

Hi Howard,

Am Wed, 26 Jun 2013 00:02:04 -0700 (PDT) schrieb Howard:

With these three examples in a single cell, say A1 & A4 & A7, I have a simple macro to put each char into a individual cell (including spaces).

What I want is a 26 char limit per line, space counts as a char.
In the first line the 26th spot falls in one of the spaces, so a break there is good to put the remaining chars on the next line.

In the second line the 26th char falls between the "YP" so in this case I need to back up to the first available space before "YP" and make the break there.

The third line is less than 26 char so it needs no split, but needs to be included in the final 'each char in an individual cell' caper.

HZG MY AG AGHTO TYMVKTZ. K RHT'M ZGM YIJ; K'A

UYQTZ. XVGT K'A KT PEYTM YP HT HQJKGTRG, HII MVHM

ZGYEZG NQETO


try:

Sub Test()
Const maxLen As Integer = 26
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String


Str1 = IIf(Len([A1]) maxLen, Left([A1], _
InStrRev([A1], " ", maxLen + 1)), [A1])

Str2 = IIf(Len([A4]) maxLen, Left([A4], _
InStrRev([A4], " ", maxLen + 1)), [A4])

Str3 = IIf(Len([A7]) maxLen, Left([A7], _
InStrRev([A7], " ", maxLen + 1)), [A7])

[A10] = Str1 & Str2 & Str3
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Text To Column max 26 characters

Hi Howard,

sorry, I didn't read carefully.
Try:

Sub Test()
Const maxLen As Integer = 26

[A1] = IIf(Len([A1]) maxLen, Left([A1], _
InStrRev([A1], " ", maxLen)), [A1])

[A4] = IIf(Len([A4]) maxLen, Left([A4], _
InStrRev([A4], " ", maxLen)), [A4])

[A7] = IIf(Len([A7]) maxLen, Left([A7], _
InStrRev([A7], " ", maxLen)), [A7])

Columns("A").TextToColumns Destination:=Range("B1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1), Array(2, 1), Array(3, 1),
_
Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1),
_
Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1),
_
Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array(23, 1),
_
Array(24, 1), Array(25, 1), Array(26, 1)), TrailingMinusNumbers:=True
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Text To Column max 26 characters

On Wednesday, June 26, 2013 12:36:31 AM UTC-7, Claus Busch wrote:
Hi Howard,



sorry, I didn't read carefully.

Try:



Sub Test()

Const maxLen As Integer = 26



[A1] = IIf(Len([A1]) maxLen, Left([A1], _

InStrRev([A1], " ", maxLen)), [A1])



[A4] = IIf(Len([A4]) maxLen, Left([A4], _

InStrRev([A4], " ", maxLen)), [A4])



[A7] = IIf(Len([A7]) maxLen, Left([A7], _

InStrRev([A7], " ", maxLen)), [A7])



Columns("A").TextToColumns Destination:=Range("B1"),

DataType:=xlFixedWidth, _

FieldInfo:=Array(Array(0, 1), Array(1, 1), Array(2, 1), Array(3, 1),

_

Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _

Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1),

_

Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1),

_

Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array(23, 1),

_

Array(24, 1), Array(25, 1), Array(26, 1)), TrailingMinusNumbers:=True

End Sub


Regards

Claus Busch


This second code nails it spot on!!
I was thinking I had an out side chance to figure it out on my own, but after seeing this work, I would have never got there.

Thanks, Claus.

Regards,
Howard
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Text To Column max 26 characters

Hi Howard,

Am Wed, 26 Jun 2013 00:50:07 -0700 (PDT) schrieb Howard:

I was thinking I had an out side chance to figure it out on my own, but after seeing this work, I would have never got there.


glad to help. Thank you for the feedback.
Instead of TextToColumns you can do it with formula:
Sub Test()
Const maxLen As Integer = 26

[A1] = IIf(Len([A1]) maxLen, Left([A1], _
InStrRev([A1], " ", maxLen)), [A1])

[A4] = IIf(Len([A4]) maxLen, Left([A4], _
InStrRev([A4], " ", maxLen)), [A4])

[A7] = IIf(Len([A7]) maxLen, Left([A7], _
InStrRev([A7], " ", maxLen)), [A7])

Range("B1:AA1").Formula = "=mid($A$1,column(A1),1)"
Range("B4.AA4").Formula = "=mid($A$4,column(A4),1)"
Range("B7:AA7").Formula = "=mid($A$7,column(A7),1)"
Range("B1:AA1").Value = Range("B1:AA1").Value
Range("B4.AA4").Value = Range("B4.AA4").Value
Range("B7:AA7").Value = Range("B7:AA7").Value

End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Text To Column max 26 characters

On Wednesday, June 26, 2013 12:54:34 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Wed, 26 Jun 2013 00:50:07 -0700 (PDT) schrieb Howard:



I was thinking I had an out side chance to figure it out on my own, but after seeing this work, I would have never got there.




glad to help. Thank you for the feedback.

Instead of TextToColumns you can do it with formula:

Sub Test()

Const maxLen As Integer = 26



[A1] = IIf(Len([A1]) maxLen, Left([A1], _

InStrRev([A1], " ", maxLen)), [A1])



[A4] = IIf(Len([A4]) maxLen, Left([A4], _

InStrRev([A4], " ", maxLen)), [A4])



[A7] = IIf(Len([A7]) maxLen, Left([A7], _

InStrRev([A7], " ", maxLen)), [A7])



Range("B1:AA1").Formula = "=mid($A$1,column(A1),1)"

Range("B4.AA4").Formula = "=mid($A$4,column(A4),1)"

Range("B7:AA7").Formula = "=mid($A$7,column(A7),1)"

Range("B1:AA1").Value = Range("B1:AA1").Value

Range("B4.AA4").Value = Range("B4.AA4").Value

Range("B7:AA7").Value = Range("B7:AA7").Value



End Sub





Regards

Claus Busch



Okay, I'll give that a try also, but I find that the previous code looses some of the text. I'm still enthused though.

If I run the code on this line only, it makes the break between the "." (period) and the next letter "K". That is perfect. However, I am now missing the rest of the line which I assumed would be placed below the first 26 max char's.

Me thinks I misled you in my explanation.

HZG MY AG AGHTO TYMVKTZ. K RHT'M ZGM YIJ; K'A

So with the line above I would want it to wind up like this.

HZG MY AG AGHTO TYMVKTZ.

K RHT'M ZGM YIJ; K'A

Then the text to columns code should run pretty much like you have it.

Howard
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 restrict a text column to a specific number of characters? Irene Threadgold Excel Discussion (Misc queries) 4 November 5th 09 09:31 PM
How to cut off characters in a text column abc[_3_] Excel Discussion (Misc queries) 3 October 12th 09 07:40 PM
Deleting characters in a column of cells -converting to text strin Chris Maddogz Excel Programming 2 June 15th 09 04:10 AM
Function to move text 65 characters to next row in column? Nat1 Excel Worksheet Functions 7 December 13th 06 05:23 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM


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