Excel Transpose duplicate name for every criteria

Fimpass

New Member
Joined
Oct 31, 2017
Messages
2
Hi all.

I got a question regarding a file that I'm working on since yesterday.
I got this table:
fWEkBJB.png


I need the data to be like this:
DveLwza.png


So If a person has 3 OK's The code needs to return the column header and create a duplicate for every column header. I got this code now.
Code:
Sub BlankLine()Dim Col As Variant, coll As Long, LastRow As Long, i As Long, j As Long, StartRow As Long, LR2 As Long


        Col = "a"
        StartRow = 1




LastRow = Sheet1.Cells(Rows.Count, Col).End(xlUp).Row


Application.ScreenUpdating = False
With ActiveSheet
j = 0
s = 1


For i = 2 To LastRow
 LR2 = Sheet2.Cells(Rows.Count, Col).End(xlUp).Row
 coll = WorksheetFunction.CountIf(Sheet1.Range("I" & i, "AG" & i), "OK")
 For j = 1 To coll
  Sheet2.Range("A" & LR2 + j).Value = Sheet1.Range("A" & i).Value
  Sheet2.Range("B" & LR2 + j).Value = Sheet1.Range("B" & i).Value
  Sheet2.Range("C" & LR2 + j).Value = Sheet1.Range("C" & i).Value
  Sheet2.Range("D" & LR2 + j).Value = Sheet1.Range("D" & i).Value
  Sheet2.Range("E" & LR2 + j).Value = Sheet1.Range("E" & i).Value
  Sheet2.Range("F" & LR2 + j).Value = Sheet1.Range("F" & i).Value
  Sheet2.Range("G" & LR2 + j).Value = Sheet1.Range("G" & i).Value
  Sheet2.Range("H" & LR2 + j).Value = Sheet1.Range("H" & i).Value
  Sheet2.Range("I" & LR2 + j).Value = Sheet1.Range("H1").Offset(0, j).Value
  s = s + 1
 Next j


Next i
End With
Application.ScreenUpdating = True




End Sub

The code above creates all I need EXCEPT "I" column that is messed up. I know that I need a variable that counts the column where the OK is and return the header, but I don't know how to make it work.

Please help a bit.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi & welcome to the board
Try this
Code:
Sub BlankLine()

Application.ScreenUpdating = False

    Dim Cl As Range
    Dim Cnt As Long

    With Sheet4
        For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
            Cnt = WorksheetFunction.Countif(Cl.Offset(, 8).Resize(, 25), "OK")
            If Not Cnt = 0 Then
                sheet9.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(1 * Cnt, 8).Value = Cl.Resize(, 8).Value
                sheet9.Range("I" & Rows.Count).End(xlUp).Offset(1).Resize(Cnt).Value = _
                    Cl.Offset(, 8).Resize(, 25).SpecialCells(xlConstants).Value
            End If
        Next Cl
    End With
    
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Forgot to mention that you'll need to change the sheet references to match yours
 
Upvote 0
name001002003004005006007008009010
billokokokokok
fredokokokokokok
bill001
bill003
bill004
bill006
bill009
fred002
fred003
fred005this macro produced the lower table
fred006
fred008Sub Macro5()
fred009'
' Macro5 Macro
' Macro recorded 31/10/2017 by bob
'
'
Dim myname(50), mytest(50)
rrow = 3
For j = 2 To 3
For k = 2 To 11
If Cells(j, k) = "ok" Then GoTo 50 Else GoTo 100
50 Sum = Sum + 1
myname(Sum) = Cells(j, 1)
mytest(Sum) = Cells(1, k)
100 Next k
For z = 1 To Sum
rrow = rrow + 1
Cells(rrow, 1) = myname(z)
Cells(rrow, 2) = mytest(z)
Next z
Sum = 0
Next j
End Sub

<colgroup><col width="64" span="14" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,525
Messages
6,125,325
Members
449,218
Latest member
Excel Master

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