Transpose sequence of cells (Hard)

Manolocs

Active Member
Joined
Mar 28, 2008
Messages
340
Hello, I am really exhausted of trying to solve this problem.
There is this spreadsheet It is a kind of questionnaire that is in different cells and I need to "transpose" cell to columns, but there are many data that must be deleted and others concatenated with spaces.
Sometimes there are more than hundreds sheets run.
I even can not explain very well without give you the sample spreadsheet.
Please take a look and let me know if this is possible to do in Excel.
Thanks in advance for your help.

https://dl.dropboxusercontent.com/u/14313867/MrExcel.xlsm
 
Hi Ombir, Thanks a lot for your time.
If you check question number 5 the alternative "d" has two lines. it is not concatenating.
I run in another big spreadsheet with 100 sheets and it only runs until sheet number 11.
Great work .
 
Last edited:
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Thanks for the Feedback Manolocs but it should run for each worksheet in workbook. Don't know why it stops at 11.

Can you share that big excel file so that I test on my PC ??
 
Upvote 0
Manolocs, Here is the revised code which is working for all 118 Sheets. Also I fixed that concatenating Issue.

Code:
Dim qs As Long, qe As Long
Dim ques As String
Dim Ws As Worksheet
Sub Manolocs()
Dim i As Long, j As Long, k As Long
Dim m As Long, n As Long
Dim ar(1 To 500) As Long
Dim Rng As Range, cell As Range
Dim ows  As Worksheet
Dim options(1 To 4) As String, tail As String
Dim opt As Range, flag As Boolean, bid As Boolean

Application.ScreenUpdating = False

On Error Resume Next
If IsError(Worksheets("Output").Range("A1")) Then
    Worksheets.Add.Name = "Output"
    Set ows = Sheets("Output")
Else
    Set ows = Sheets("Output")
End If

ows.UsedRange.ClearContents
ows.Range("A1:H1") = Array("Nr.", "ID", "ID Nr.", "Question", "Opt1", "Opt2", "Opt3", "Opt4")
m = 2

For Each Ws In Worksheets
    If Ws.Name <> ows.Name Then
    With Ws
        lr = .Cells(Rows.Count, 1).End(xlUp).Row
        Set Rng = .Range("B1:B" & lr)
        i = 1
        For Each cell In Rng
            If cell.Value Like "#" Or cell.Value Like "##" Or cell.Value Like "###" Then
                bid = id(cell)
                If bid Then
                    ar(i) = cell.Row
                    i = i + 1
                End If
            End If
        Next
        ar(i) = lr
        i = 0
        For j = 1 To lr
            q = .Cells(j, 2).Value
            If q Like "#" Or q Like "##" Or q Like "###" Then
              bid = id(.Cells(j, 2))
              If bid Then
              n = 2
              i = i + 1
              qs = j
              qe = ar(i + 1) - 1
                For k = qs To qe
                    Set opt = .Cells(k, 1)
                  If Len(opt.Value) <> 0 Then
                  flag = cans(opt)
                  tail = opt.Offset(1, 1).Value
                    If flag And opt.Value Like "[a-d] *" Then
                        If tail <> .Cells(j, 2).Value + 1 Then
                            options(1) = Mid(opt.Value, 3) + " " + tail
                        Else
                            options(1) = Mid(opt.Value, 3)
                        End If
                    ElseIf opt.Value Like "[a-d] *" Then
                        If tail <> .Cells(j, 2).Value + 1 Then
                            options(n) = Mid(opt.Value, 3) + " " + tail
                        Else
                            options(n) = Mid(opt.Value, 3)
                        End If
                        n = n + 1
                    End If
                  End If
                Next
                Call question
                With ows
                    .Cells(m, 1) = Ws.Cells(j, 2)
                    .Cells(m, 2) = "Id"
                    .Cells(m, 3) = Ws.Cells(j, 2).Offset(1, 0)
                    .Cells(m, 4) = ques
                    .Cells(m, 5).Resize(, 4) = options
                    m = m + 1
                End With
            End If
            End If
        Erase options
        ques = ""
        Next
    End With
    End If
    Erase ar
Next
Application.ScreenUpdating = True
End Sub
Function cans(optn As Range) As Boolean
cans = False
If optn.Characters(3, 1).Font.Bold And optn.Text <> "id" Then
        cans = True
End If
End Function
Sub question()
Do While qs <> qe
    ques = ques + Ws.Cells(qs, 3) + " "
    qs = qs + 1
Loop
End Sub
Function id(qno As Range) As Boolean
    id = False
    If qno.Characters(1, 1).Font.Bold Then
        id = True
    End If
End Function

Here is the link to download sample workbook.

MrExcelFinaltest.xlsm - Send Files Online - TempSend.com

Regards,
Ombir
 
Upvote 0
Dear Ombir, It is working perfect, you saved me a lot of work..... Save my day :)
Thanks a lot,
 
Upvote 0

Forum statistics

Threads
1,215,328
Messages
6,124,295
Members
449,149
Latest member
mwdbActuary

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