Advertisement
YasserKhalil2019

T4505_Fill School Table Using Arrays

Jan 8th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. https://excel-egy.com/forum/t4505
  2. ---------------------------------
  3.  
  4. Sub Fill_School_Table_Using_Arrays()
  5. Dim a, b, x, ws As Worksheet, sh As Worksheet, foug As String, i As Long, j As Long, c As Long
  6.  
  7. Application.ScreenUpdating = False
  8. Set ws = ThisWorkbook.Worksheets(1)
  9. Set sh = ThisWorkbook.Worksheets(2)
  10. sh.Range("E9:X16").ClearContents
  11. a = ws.Range("B3:P" & ws.Cells(Rows.Count, "B").End(xlUp).Row).Value
  12. ReDim b(1 To 8, 1 To 20)
  13. foug = sh.Range("L5").Value
  14.  
  15. For i = LBound(a) To UBound(a)
  16. If a(i, 7) = foug Then
  17. x = Application.Match(a(i, 6), sh.Range("E7:U7"), 0)
  18. If Not IsError(x) Then
  19. c = x
  20. For j = 1 To 8
  21. If a(i, 1) = j Then
  22. b(j, c) = IIf(b(j, c) = Empty, a(i, 2), b(j, c) & "|" & a(i, 2))
  23. b(j, c + 1) = IIf(b(j, c + 1) = Empty, a(i, 3), b(j, c + 1) & "|" & a(i, 3))
  24. b(j, c + 2) = IIf(b(j, c + 2) = Empty, a(i, 8), b(j, c + 2) & "|" & a(i, 8))
  25. b(j, c + 3) = IIf(b(j, c + 3) = Empty, a(i, 10), b(j, c + 3) & "|" & a(i, 10))
  26. End If
  27. Next j
  28. End If
  29. End If
  30. Next i
  31.  
  32. sh.Range("E9").Resize(UBound(b, 1), UBound(b, 2)).Value = b
  33. Application.ScreenUpdating = True
  34. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement