Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2018, 05:47 AM
mthwi mthwi is offline Splitting paragraphs in cells into several cells Windows 10 Splitting paragraphs in cells into several cells Office 2016
Novice
Splitting paragraphs in cells into several cells
 
Join Date: Nov 2017
Posts: 5
mthwi is on a distinguished road
Default Splitting paragraphs in cells into several cells

Hello, everyone,


i have uploaded the following table.
In worksheet 'Before' is the before-state (1. Image below)
See document Before.png.

In the worksheet 'After' is the after-state (2. Image blow)
See document After.png.

I also attached an excel file.

The cells containing texts with paragraphs are to be distributed on cells.
It is important that the number of columns and rows can vary.
This is just a small example.

I am looking forward to a solution. VBA would be great.

Thanks and greetings.
Attached Images
File Type: png Before.png (118.1 KB, 18 views)
File Type: png After.png (119.9 KB, 18 views)
Attached Files
File Type: xlsx forum.xlsx (10.8 KB, 12 views)
Reply With Quote
  #2  
Old 01-17-2018, 08:09 AM
NoSparks NoSparks is offline Splitting paragraphs in cells into several cells Windows 7 64bit Splitting paragraphs in cells into several cells Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

Are you sure that row 8 from the "Before" sheet is to result in row 14 on the "After" sheet ?
Reply With Quote
  #3  
Old 01-25-2018, 05:27 PM
p45cal's Avatar
p45cal p45cal is offline Splitting paragraphs in cells into several cells Windows 10 Splitting paragraphs in cells into several cells Office 2010 32bit
Expert
 
Join Date: Apr 2014
Posts: 947
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

In the attached is a macro blah, which can be run by clicking the button on sheet Before. It asks for the source range to process which initially defaults to an area beginning at row 4 (because I doubt you'll want to process row 3). If you don't cancel at this stage then it'll then ask for a destination range, which I've initially defaulted to A24 of the After sheet. Again, if you don't cancel it'll process what you've asked it to and put the results at the destination.

For those interested this is the code:
Code:
Sub blah()
Dim Rng As Range, Destn As Range
Static SourceRngAddress As String
Static DestnAddress As String
If SourceRngAddress = "" Then SourceRngAddress = "A4:F11"
On Error Resume Next
Set Rng = Application.InputBox("Select range to process…", "Select range", SourceRngAddress, Type:=8)
On Error GoTo 0
If Not Rng Is Nothing Then
  SourceRngAddress = Rng.Address(External:=True)
  If DestnAddress = "" Then DestnAddress = "After!$A$24"
  On Error Resume Next
  Set Destn = Application.InputBox("Select destination…", "Select range", DestnAddress, Type:=8)
  On Error GoTo 0
  If Not Destn Is Nothing Then
    DestnAddress = Destn.Address(External:=True)

    x = Rng
    ReDim RowsNeeded(1 To UBound(x))
    For rw = 1 To UBound(x)
      MaxLinesCount = -9
      For Colm = 1 To UBound(x, 2)
        y = Split(x(rw, Colm), vbLf)
        LinesCount = UBound(y)
        MaxLinesCount = Application.Max(MaxLinesCount, LinesCount)
      Next Colm
      '  Rng.Rows(rw).Select
      '  MsgBox rw & " has " & MaxLinesCount + 1 & " lines"
      RowsNeeded(rw) = MaxLinesCount + 1
    Next rw
    xx = Application.Sum(RowsNeeded)
    ReDim Results(1 To xx, 1 To UBound(x, 2))
    DestnRow1 = 1
    For rw = 1 To UBound(x)
      For Colm = 1 To UBound(x, 2)
        DestnRow = DestnRow1
        y = Split(x(rw, Colm), vbLf)
        For i = LBound(y) To UBound(y)
          Results(DestnRow, Colm) = y(i)
          DestnRow = DestnRow + 1
        Next i
      Next Colm
      DestnRow1 = DestnRow1 + RowsNeeded(rw)
    Next rw
    Destn.Resize(UBound(Results), UBound(Results, 2)).Value = Results
    Application.Goto Destn
  End If
End If
End Sub
Attached Files
File Type: xlsm MSOForums37915forum.xlsm (24.7 KB, 10 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting paragraphs in cells into several cells Splitting Cells in a Very Large Table Paulvana Word 4 01-06-2017 01:52 PM
Splitting paragraphs in cells into several cells Linking cells: can sub-cells move with their master-cell when sorting? kw01 Excel 1 06-30-2015 05:02 PM
Copying text range of cells to different cells adds an extra line jpb103 Word VBA 2 07-23-2014 12:22 PM
Splitting paragraphs in cells into several cells Preventing cells from splitting into two pages Jaymond Flurrie Word VBA 1 05-11-2011 06:54 PM
Paragraphs vanishing in multi line cells teknetia Word Tables 0 08-02-2009 10:50 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft