View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 2
Default Moving extra characters to a new column

On Dec 30, 12:25*pm, Ron Rosenfeld wrote:
On Thu, 30 Dec 2010 11:53:42 -0800 (PST), Tom wrote:
I am reformatting spreadsheets so they can be uploaded into a
database, and need to make sure that there are no more than 255
characters in each cell. *I don't want to lose the information though,
so is there VBA code I could use that would take any text over the 255
limit and move it into the cell immediatly to the the right?


Thanks


And if there are more than 255*2 characters?

This will just fill to the right with a maximum of 255 characters per cell.

You'll need to ensure the target range is clear.

=======================
Option Explicit
Sub Max255Chars()
* * Dim rg As Range, c As Range
* * Dim L As Long
* * Dim S As String
Set rg = Selection
For Each c In Selection
* S = c.Text
* * For L = 1 To Len(S) Step 255
* * * * c(1, L \ 255 + 1).Value = Mid(S, L, 255)
* * Next L
Next c
End Sub
==========================


Thank you that is very helpful. Now can just run the macro in the top
cell of the column and drag it all the way down and it will still work
or does it need to be run individually?