Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

Download:

Datei 1: Text trennen.xlsm

Excel Macro: Divide text into columns with a maximum of 132 characters,

 

where words must not be separated

 

 

Option Explicit On

 

Const max_length = 132

 

Public Sub Text_in_Spalten_maxLength()

    '------------< Text_in_Spalten_maxLength() >------------

    Dim sheet As Worksheet

    Set sheet = ActiveSheet

   

    Dim cell As Range

    For Each cell In sheet.Range("A2:A100")

        Dim sText As String

        sText = cell.Text

 

        Dim iRow As Integer

        iRow = cell.Row

 

        If sText Like "" Then Exit Sub

        Dim arrWords

        arrWords = Split(sText, " ")

 

        Dim iCol As Integer

        iCol = 2

        Dim varWord

        Dim sTextMax As String

 

        For Each varWord In arrWords

            sTextMax = sTextMax & " " & varWord

            If Len(sTextMax) < max_length Then

 

            Else

                sTextMax = Replace(sTextMax, " ", "", 1, 1)

                sheet.Cells(iRow, iCol) = sTextMax

                sTextMax = ""

                iCol = iCol + 1

            End If

 

        Next

        sTextMax = Replace(sTextMax, " ", "", 1, 1)

        sheet.Cells(iRow, iCol) = sTextMax

 

    Next

 

 

    '------------</ Text_in_Spalten_maxLength() >------------

End Sub

 

 

Mobile

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de