Locatin


SUBMITTED BY: Guest

DATE: Nov. 19, 2013, 3:19 a.m.

FORMAT: Text only

SIZE: 4.5 kB

HITS: 670

  1. Location Category Supplier
  2. A Computers Company X
  3. A Printers Company Y
  4. B Computers Company X
  5. B Printers Company Y
  6. B Software Company Y
  7. C Computers Company Y
  8. C Software Company Z
  9. Computers Printers Software
  10. A Company X Company Y
  11. B Company X Company Y Company Y
  12. C Company Y Company Z
  13. SELECT t1.Location, MAX(t1.Computers), MAX(t1.Printers), MAX(t1.Software)
  14. FROM (
  15. SELECT
  16. t.Location,
  17. CASE WHEN t.Category = 'Computers' THEN
  18. t.Supplier
  19. END Computers,
  20. CASE WHEN t.Category = 'Printers' THEN
  21. t.Supplier
  22. END Printers,
  23. CASE WHEN t.Category = 'Software' THEN
  24. t.Supplier
  25. END Software,
  26. FROM
  27. YOUR_TABLE t
  28. ) t1
  29. GROUP BY t1.Location
  30. ' Get table entry from third column of list.
  31. TableEntry = Cells(ListRow, 3).Value
  32. On Error Resume Next
  33. If Err.Number > 0 Then MsgBox Err.Number
  34. ' Get position of product name within range of row titles.
  35. If TableEntry <> "" Then
  36. TableRow = Application.Match(Cells(ListRow, 1), Range("F3:" & MYLastRowAddress), 0) ' 2 rows less than reality
  37. ' Get position of product size within range of column titles.
  38. TableColumn = Application.Match(Cells(ListRow, 2), Range("G2:" & MYLastColAddress), 0)
  39. Set CellToFill = Range("F2").Offset(TableRow, TableColumn)
  40. ' If there's already an entry in the cell, separate it from the new entry with a comma and space.
  41. If Err.Number = 0 Then
  42. If CellToFill.Value <> "" Then
  43. CellToFill.Value = CellToFill.Value & ","
  44. CellToFill.Value = CellToFill.Value & TableEntry
  45. Else
  46. CellToFill.Value = TableEntry
  47. End If
  48. Else
  49. MisMatchCounter = MisMatchCounter + 1
  50. Sheets("Errors").Cells(MisMatchCounter, 1).Value = ListRow
  51. Sheets("Errors").Cells(MisMatchCounter, 2).Value = Cells(ListRow, 1)
  52. Sheets("Errors").Cells(MisMatchCounter, 3).Value = Cells(ListRow, 2)
  53. Sheets("Errors").Cells(MisMatchCounter, 4).Value = Cells(ListRow, 3)
  54. Sheets("Errors").Cells(MisMatchCounter, 5).Value = Cells(ListRow, 4)
  55. End If
  56. End If
  57. On Error GoTo 0
  58. ListRow = ListRow + 1
  59. Dim TableRow, TableColumn As Integer
  60. Dim TableEntry As String
  61. Dim CellToFill As Range
  62. 'Sheet is called Lijst
  63. 'Column A is names for top row
  64. 'Column B is names for left column
  65. 'Column C is value for Matrix
  66. 'Matrix Top Row starts at H1
  67. 'Matrix Left Column starts at G2
  68. MatrixLastColAddress = Range("H1").End(xlToRight).Address
  69. MatrixLastRow = Range("G65536").End(xlUp).Row
  70. LijstReadColumn = 3
  71. LijstCurrentRow = 2 'make 1 if no header is used
  72. Do Until Sheets("Lijst").Cells(LijstCurrentRow, 1).Value = ""
  73. ' Get table entry from third column of list.
  74. TableEntry = Sheets("Lijst").Cells(LijstCurrentRow, LijstReadColumn).Value
  75. ' Get position of Employee name within Matrix.
  76. TableColumn = Application.Match(Sheets("Lijst").Cells(LijstCurrentRow, 1), Range("H1:" & MatrixLastColAddress), 0)
  77. ' Get position of Qualification Name within Matrix titles.
  78. TableRow = Application.Match(Sheets("Lijst").Cells(LijstCurrentRow, 2), Range("G2:G" & MatrixLastRow), 0)
  79. Set CellToFill = Range("G1").Offset(TableRow, TableColumn)
  80. ' If there's already an entry in the cell, separate it from the new entry with a comma and space.
  81. If CellToFill.Value <> "" Then CellToFill.Value = CellToFill.Value & ","
  82. ' Add the new entry to the cell.
  83. CellToFill.Value = CellToFill.Value & TableEntry
  84. LijstCurrentRow = LijstCurrentRow + 1
  85. Loop
  86. Select Location
  87. , Min( Case When Category = 'Computers' Then Supplier End ) As Computers
  88. , Min( Case When Category = 'Printers' Then Supplier End ) As Printers
  89. , Min( Case When Category = 'Software' Then Supplier End ) As Software
  90. From MyTable
  91. Group By Location

comments powered by Disqus