VBA from wrapped cells to multiple row

Dampa88

Board Regular
Joined
Apr 28, 2016
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Dear all,

I'm here again to ask you some inputs.

I created an online form to collect some information from colleagues.
One question allows long text, incluging multiple lines.

When I export to Excel, the multiple lines appear as "wrapped text". Basically, I'd need to convert wrapped text into multiple lines in order to do vlookups and so on.
Additional "Choice" must be copied for these new lines. For this last part I should have no problem, however I'm blocked with the first main step.

Is there any quick code to do this?

In the example below I indicated some possible values for "Free text". What's in common are the new lines. We can have also empty lines (to take out).
Column is A but in the real file is not.


Thanks in advance,
D

From:

Test Forms.xlsx
AB
1Free TextChoice
299968548462541800 99968850854105480Option A;
399489098409840980 Option B;
499934534656799567 99978978978956755 100000056482 Option A;Option B;
5009996854846254180 9999856756756756 100001567568Option C;
Sheet2


To:

Test Forms.xlsx
AB
1Free TextChoice
299968548462541800Option A;
399968850854105480Option A;
499489098409840980Option B;
599934534656799567Option A;Option B;
699978978978956755Option A;Option B;
7100000056482Option A;Option B;
8009996854846254180Option C;
99999856756756756Option C;
10100001567568Option C;
Sheett3
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Dear all,

Googling I have understood more about the "carriage return" and then I have been able to solve my problem.

VBA Code:
Public Sub separate_line_break()
    target_col = "A"     'Define the column you want to break
    ColLastRow = Range(target_col & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For Each Rng In Range(target_col & "1" & ":" & target_col & ColLastRow)
        If InStr(Rng.Value, vbLf) Then
            Rng.EntireRow.Copy
            Rng.EntireRow.Insert
            Rng.Offset(-1, 0) = Mid(Rng.Value, 1, InStr(Rng.Value, vbLf) - 1)
            Rng.Value = Mid(Rng.Value, Len(Rng.Offset(-1, 0).Value) + 2, Len(Rng.Value))
        End If
    Next
    
    ColLastRow2 = Range(target_col & Rows.Count).End(xlUp).Row
    For Each Rng2 In Range(target_col & "1" & ":" & target_col & ColLastRow2)
        If Len(Rng2) = 0 Then
            Rng2.EntireRow.Delete
        End If
    Next
    Application.ScreenUpdating = True
End Sub

Quote: External link
 
Upvote 0

Forum statistics

Threads
1,215,856
Messages
6,127,362
Members
449,381
Latest member
Aircuart

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top