a | b | |
---|
| 0 | + | Sub Swap(a, x, y) |
---|
| 0 | + | Dim i |
---|
| 0 | + | Dim t |
---|
| 0 | + | ReDim t(LBound(a, 1) To UBound(a, 1)) |
---|
| 0 | + | For i = LBound(a, 1) To UBound(a, 1) |
---|
| 0 | + | t(i) = a(i, x) |
---|
| 0 | + | Next |
---|
| 0 | + | For i = LBound(a, 1) To UBound(a, 1) |
---|
| 0 | + | a(i, x) = a(i, y) |
---|
| 0 | + | Next |
---|
| 0 | + | For i = LBound(a, 1) To UBound(a, 1) |
---|
| 0 | + | a(i, y) = t(i) |
---|
| 0 | + | Next |
---|
| 0 | + | End Sub |
---|
| 0 | + | |
---|
| 0 | + | Sub Sort(a, row, keys As Scripting.Dictionary) |
---|
| 0 | + | Dim i |
---|
| 0 | + | Dim j |
---|
| 0 | + | For i = LBound(a, 1) To UBound(a, 1) - 1 |
---|
| 0 | + | For j = LBound(a, 1) To UBound(a, 1) - 1 |
---|
| 0 | + | If keys(a(row, j)) < keys(a(row, j + 1)) Then |
---|
| 0 | + | Call Swap(a, j, j + 1) |
---|
| 0 | + | End If |
---|
| 0 | + | Next |
---|
| 0 | + | Next |
---|
| 0 | + | End Sub |
---|
| 0 | + | |
---|
| 0 | + | Function GetSheet(rowNum As Long) As Excel.Worksheet |
---|
| 0 | + | Set GetSheet = Excel.Worksheets(rowNum + 1) |
---|
| 0 | + | End Function |
---|
| 0 | + | |
---|
| 0 | + | Function GetRels_2(sh As Excel.Worksheet, c As String) As Scripting.Dictionary |
---|
| 0 | + | Dim r As Scripting.Dictionary |
---|
| 0 | + | Set r = New Scripting.Dictionary |
---|
| 0 | + | Dim j As Long |
---|
| 0 | + | Dim i As Excel.Range |
---|
| 0 | + | For Each i In sh.Range("B1:D1").Columns |
---|
| 0 | + | If i.Value = c Then |
---|
| 0 | + | j = i.Column |
---|
| 0 | + | Exit For |
---|
| 0 | + | End If |
---|
| 0 | + | Next |
---|
| 0 | + | For Each i In sh.Range("A2:D4").Rows |
---|
| 0 | + | Call r.Add(i.Columns(1).Value, i.Columns(j)) |
---|
| 0 | + | Next |
---|
| 0 | + | Set GetRels_2 = r |
---|
| 0 | + | End Function |
---|
| 0 | + | |
---|
| 0 | + | Function GetRels(rowNum As Long, c As String) As Scripting.Dictionary |
---|
| 0 | + | Set GetRels = GetRels_2(GetSheet(rowNum), c) |
---|
| 0 | + | End Function |
---|
| 0 | + | |
---|
| 0 | + | Function GetColor(r As Long) As Long |
---|
| 0 | + | If r = 5 Then |
---|
| 0 | + | GetColor = RGB(255, 0, 0) |
---|
| 0 | + | ElseIf r = 3 Then |
---|
| 0 | + | GetColor = RGB(255, 128, 128) |
---|
| 0 | + | ElseIf r = 1 Then |
---|
| 0 | + | GetColor = RGB(255, 192, 192) |
---|
| 0 | + | ElseIf r = 0 Then |
---|
| 0 | + | GetColor = RGB(255, 224, 224) |
---|
| 0 | + | Else |
---|
| 0 | + | Call Err.Raise(1, "invalid relative") |
---|
| 0 | + | End If |
---|
| 0 | + | End Function |
---|
| 0 | + | |
---|
| 0 | + | Function GetColors_2(rels As Scripting.Dictionary) As Scripting.Dictionary |
---|
| 0 | + | Dim c As Scripting.Dictionary |
---|
| 0 | + | Set c = New Scripting.Dictionary |
---|
| 0 | + | Dim i |
---|
| 0 | + | For Each i In rels.keys |
---|
| 0 | + | Call c.Add(i, GetColor(rels(i))) |
---|
| 0 | + | Next |
---|
| 0 | + | Set GetColors_2 = c |
---|
| 0 | + | End Function |
---|
| 0 | + | |
---|
| 0 | + | Function GetColors(rowNum As Long, c As String) As Scripting.Dictionary |
---|
| 0 | + | Set GetColors = GetColors_2(GetRels(rowNum, c)) |
---|
| 0 | + | End Function |
---|
| 0 | + | |
---|
| 0 | + | Sub Main() |
---|
| 0 | + | Dim rowNum As Long |
---|
| 0 | + | Dim char1 As String |
---|
| 0 | + | rowNum = Excel.Selection.row |
---|
| 0 | + | char1 = Excel.Selection.Value |
---|
| 0 | + | |
---|
| 0 | + | ' Sort |
---|
| 0 | + | Dim v As Variant |
---|
| 0 | + | Dim sh1 As Excel.Worksheet |
---|
| 0 | + | Dim range1 As Excel.Range |
---|
| 0 | + | Set sh1 = Excel.Worksheets(1) |
---|
| 0 | + | Set range1 = sh1.Range("A1:C3") |
---|
| 0 | + | v = range1.Value |
---|
| 0 | + | Call Sort(v, 1, GetRels(rowNum, char1)) |
---|
| 0 | + | range1.Value = v |
---|
| 0 | + | |
---|
| 0 | + | ' Coloring |
---|
| 0 | + | Dim c As Scripting.Dictionary |
---|
| 0 | + | Dim i As Excel.Range |
---|
| 0 | + | Dim j As Excel.Range |
---|
| 0 | + | Dim colNum As Long |
---|
| 0 | + | colNum = 1 |
---|
| 0 | + | For Each i In range1.Rows(rowNum).Columns |
---|
| 0 | + | If i.Value = char1 Then |
---|
| 0 | + | Exit For |
---|
| 0 | + | End If |
---|
| 0 | + | colNum = colNum + 1 |
---|
| 0 | + | Next |
---|
| 0 | + | For Each i In range1.Rows |
---|
| 0 | + | Set c = GetColors(i.row, i.Columns(colNum).Value) |
---|
| 0 | + | For Each j In i.Columns |
---|
| 0 | + | j.Interior.Color = c(j.Value) |
---|
| 0 | + | Next |
---|
| 0 | + | Next |
---|
| 0 | + | End Sub |
---|
... | |
---|