Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
On Error Resume Next
Dim arrTemp, i
Dim iColumn, iRow
iColumn = Target.Column
iRow = Target.Row
If Not Intersect([A1:A100], Target) Is Nothing Then
'Target = Replace(Target, " " & Evaluate("DC"), Chr(10) & Evaluate("DC"), 1)
'Target = BreakByLen(Target, 10)
arrTemp = Split(BreakByLen(Target, 10), Chr(10))
For i = LBound(arrTemp) To UBound(arrTemp)
Cells(iRow, iColumn) = arrTemp(i)
iRow = iRow + 1
Next
End If
Application.EnableEvents = True
End Sub
Function BreakByLen(ByVal strSource As String, ByVal iLength As Long) As String
If iLength <= 0 Then
BreakByLen = strSource
Exit Function
End If
Dim strRet As String
Dim iPos As Integer
Dim strTemp As String
strRet = ""
strTemp = ""
Do While Len(strSource) > iLength
strTemp = Mid(strSource, 1, iLength)
iPos = InStr(strTemp, Chr(10))
If iPos = 0 Then iPos = InStrRev(strTemp, " ")
If iPos > 0 Then strTemp = Mid(strTemp, 1, iPos - 1)
If Mid(strSource, Len(strTemp) + 1, 1) = Chr(10) Then
strSource = Mid(strSource, Len(strTemp) + 2)
Else
strSource = Mid(strSource, Len(strTemp) + 1)
End If
strRet = strRet & strTemp & Chr(10)
Loop
BreakByLen = strRet & strSource
End Function