Advertisement
YasserKhalil2019

T3853_Transfer Matrix From Sheet To Another Using Arrays

Sep 5th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. https://excel-egy.com/forum/t3853
  2. ---------------------------------
  3.  
  4. Sub Transfer_Matrix_From_Sheet_To_Another_Using_Arrays()
  5. Dim a, v, b, ws As Worksheet, sh As Worksheet, i As Long, j As Long, k As Long
  6.  
  7. Application.ScreenUpdating = False
  8. Set ws = ThisWorkbook.Worksheets("Input")
  9. Set sh = ThisWorkbook.Worksheets("Load")
  10.  
  11. a = ws.Range("A4").CurrentRegion.Value
  12. v = Application.Index(ws.Range("F4:P4").Value, 0)
  13. ReDim b(1 To UBound(a) * UBound(v), 1 To 5)
  14.  
  15. For i = LBound(v) To UBound(v)
  16. For j = 5 To UBound(a)
  17. If a(j, 1) <> Empty Then
  18. If a(j, i + 5) <> Empty Then
  19. k = k + 1
  20. b(k, 2) = a(4, i + 5)
  21. b(k, 3) = a(j, 1)
  22. b(k, 5) = a(j, i + 5)
  23. End If
  24. End If
  25. Next j
  26. Next i
  27.  
  28. sh.Rows("2:" & sh.UsedRange.Rows.Count).ClearContents
  29. sh.Range("A2").Resize(k, UBound(b, 2)).Value = b
  30. Application.ScreenUpdating = True
  31. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement