Advertisement
YasserKhalil2019

T4128_Tabular Transpose Using Formulas Within Arrays

Oct 16th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. https://excel-egy.com/forum/t4128
  2. ---------------------------------
  3.  
  4. Sub Tabular_Transpose_Using_Formulas_Inside_Arrays()
  5. Dim a, b, i As Long, j As Long, k As Long
  6.  
  7. a = Sheets("Sheet1").Range("B2:E" & Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row).Value
  8. ReDim b(1 To UBound(a, 1) * 3, 1 To 5)
  9. k = 1
  10.  
  11. For j = LBound(a, 2) + 1 To UBound(a, 2)
  12. For i = LBound(a, 1) To UBound(a, 1)
  13. If Not IsEmpty(a(i, j)) And i <> 1 Then
  14. b(k, 1) = a(i, 1)
  15. b(k, 2) = "=INDEX(Sheet2!$B$3:$B$26,MATCH(R" & k + 1 & ",Sheet2!$A$3:$A$26,0))"
  16. b(k, 3) = a(i, j)
  17. b(k, 4) = "=INDEX(Sheet2!$C$3:$C$26,MATCH(R" & k + 1 & ",Sheet2!$A$3:$A$26,0))"
  18. b(k, 5) = a(1, j)
  19. k = k + 1
  20. End If
  21. Next i
  22. Next j
  23.  
  24. Application.ScreenUpdating = False
  25. With Sheets("Sheet1").Range("P1")
  26. .Resize(, UBound(b, 2)).Value = Array("Date", "F1", "Value", "F2", "Category")
  27. .Offset(1).Resize(k - 1, UBound(b, 2)).Value = b
  28. End With
  29. Application.ScreenUpdating = True
  30. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement