Combine a Variable Number of Rows in Excel Based on Cell Contents

zerocontinues

New Member
Joined
Feb 7, 2018
Messages
3
Hey everyone,

Please help me pass the CPCU (a massive set of insurance tests). I'd like to combine rows of text in excel, to upload into a flashcard program. The format I start with looks something like this (each line would be its on its own row in its own cell):

293. Business intelligence refers to:
A. The skills technologies applications
and reinforce information integrity.
B. A collection of information stored in discrete units for ease of retrieval manipulation
combination or other computer processing.
C. The percentage of policies in force that are renewed at the policy anniversary.
D. A small segment of a total market.
294. When determining the return on investment that new information technology would produce all of
the following are costs insurers should consider EXCEPT:
A. The value of the staff’s time for training.
B. The costs of maintaining the technology.
C. The salary and benefit costs eliminated through staff reductions.
D. The value of time lost until staff become proficient using the new technology.

<tbody>
</tbody>



I need to end up with something like this:

293. Business intelligence refers to:
A. The skills technologies applications
and reinforce information integrity.
B. A collection of information stored in discrete units for ease of retrieval manipulation
combination or other computer processing.
C. The percentage of policies in force that are renewed at the policy anniversary.
D. A small segment of a total market.
294. When determining the return on investment that new information technology would produce all of
the following are costs insurers should consider EXCEPT:
A. The value of the staffÂ’s time for training.
B. The costs of maintaining the technology.
C. The salary and benefit costs eliminated through staff reductions.
D. The value of time lost until staff become proficient using the new technology.

<tbody>
</tbody>


The questions take up a varying number of rows. The only constant is that the next number in the sequence will signify a new question. There are thousands of questions I have so this would be a huge help!! Thank you!

<tbody>
</tbody>
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hope this helps.

Code:
Sub test()
Dim i As Long, LR As Long, j As Long
Dim buf As String, x
LR = cells(Rows.count, 1).End(xlUp).Row
buf = Range("A2").Value
j = 2
For i = 3 To LR
    On Error Resume Next
    x = Left(cells(i, 1).Value, 1) * 1
    If x = Empty Then x = Left(cells(i, 1).Value, 1)
    On Error GoTo 0
    If VarType(x) = 8 Then
        buf = buf & vbCrLf & cells(i, 1).Value
        x = ""
    Else
        cells(j, 2).Value = buf
        j = j + 1
        buf = cells(i, 1).Value
        x = ""
    End If
Next
 cells(j, 2).Value = buf
End Sub
 
Upvote 0
Perhaps
Code:
Sub test()
    Dim outRow As Long, arrOut() As String
    Dim oneCell As Range, inRange As Range
    
    With Range("A:A")
        Set inRange = Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
    End With
    
    ReDim arrOut(1 To inRange.Cells.Count, 1 To 1)

    For Each oneCell In inRange
        If 0 < Val(oneCell.Value) Then outRow = outRow + 1
        arrOut(outRow, 1) = arrOut(outRow, 1) & vbCr & oneCell.Value
    Next oneCell
    
    Range("c1").Resize(outRow, 1).Value = arrOut
End Sub
 
Upvote 0
Mike Ericson - I'm hoping you could make one small change. Is it possible to enter a carriage return after each cell that is input into the newly created cell?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,155
Members
449,208
Latest member
emmac

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