Advertisement
Guest User

KeyValue Highlighting Issue

a guest
Apr 1st, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Sub validateList(ByVal ListRange As Range)
  2. Dim List As Dictionary
  3. Dim Problem As Dictionary
  4. Dim Items() As String
  5. Dim Pairs() As String
  6. Dim Item As Variant
  7. Dim Pair As Variant
  8. Dim Output As String
  9. Dim Position As Integer
  10.  
  11.     Set List = New Dictionary
  12.     Set Problem = New Dictionary
  13.    
  14.     Items = Split(ListRange.Value, Main.LST_SEPERATOR)
  15.    
  16.     Invalid = ""
  17.    
  18.     For Each Item In Items
  19.         Item = Trim(Item)
  20.         Pairs = Split(Item, Main.QTY_SEPERATOR)
  21.         For Each Pair In Pairs
  22.             Pair = Trim(Pair)
  23.         Next Pair
  24.         Select Case UBound(Pairs)
  25.         Case 1
  26.             ' Part and Quantity
  27.            If CStr(Main.parseInteger(Pairs(0))) = Pairs(0) Then
  28.                 ' Pairs(0) Probably Quantity
  29.                If CStr(Main.parseInteger(Pairs(1))) = Pairs(1) Then
  30.                     ' Problem! Both Pairs(0) and Pairs(1) are Numbers
  31.                    Problem.Add Pairs(0) & Main.QTY_SEPERATOR & Pairs(1), 0
  32.                 Else
  33.                     ' Pairs(0) = Quantity, Pairs(1) = Part
  34.                    If List.Exists(Pairs(1)) = False Then
  35.                         List.Add Pairs(1), Main.parseInteger(Pairs(0))
  36.                     Else
  37.                         List(Pairs(1)) = List(Pairs(1)) + Main.parseInteger(Pairs(0))
  38.                     End If
  39.                 End If
  40.             Else
  41.                 ' Pairs(0) Probably Part
  42.                If CStr(Main.parseInteger(Pairs(1))) = Pairs(1) Then
  43.                     ' Pairs(0) = Part, Pairs(1) = Quantity
  44.                    If List.Exists(Pairs(0)) = False Then
  45.                         List.Add Pairs(0), Main.parseInteger(Pairs(1))
  46.                     Else
  47.                         List(Pairs(0)) = List(Pairs(0)) + Main.parseInteger(Pairs(1))
  48.                     End If
  49.                 Else
  50.                     ' Problem! Both Pairs(0) and Pairs(1) are Strings
  51.                    Problem.Add Pairs(0) & Main.QTY_SEPERATOR & Pairs(1), 0
  52.                 End If
  53.             End If
  54.         Case 0
  55.             ' Part Only
  56.            If List.Exists(Pairs(0)) = False Then
  57.                 List.Add Pairs(0), 1
  58.             Else
  59.                 List(Pairs(0)) = List(Pairs(0)) + 1
  60.             End If
  61.         Case Else
  62.             Problem.Add Item, 0
  63.         End Select
  64.     Next Item
  65.    
  66.     Position = 1
  67.    
  68.     ListRange.Value = ""
  69.    
  70.     For Each Item In Problem.Keys
  71.         If Not ListRange.Value = "" Then
  72.             ListRange.Value = ListRange.Value & ", "
  73.             Debug.Print Position
  74.             With ListRange.Characters(Start:=Position, Length:=2)
  75.                 .Font.Color = RGB(0, 0, 0)
  76.                 .Font.Bold = False
  77.             End With
  78.             Position = Position + 2
  79.         End If
  80.        
  81.         Output = Item
  82.  
  83.         ListRange.Value = ListRange.Value & Output
  84.         With ListRange.Characters(Start:=Position, Length:=Len(Item))
  85.             .Font.Color = RGB(255, 0, 0)
  86.             .Font.Bold = True
  87.         End With
  88.         Position = Position + Len(Item)
  89.     Next Item
  90.    
  91.     For Each Item In List.Keys
  92.         If Not ListRange.Value = "" Then
  93.             ListRange.Value = ListRange.Value & ", "
  94.             With ListRange.Characters(Start:=Position, Length:=2)
  95.                 .Font.Color = RGB(0, 0, 0)
  96.                 .Font.Bold = False
  97.             End With
  98.             Position = Position + 2
  99.         End If
  100.  
  101.         If List(Item) = 1 Then
  102.             Output = Item
  103.         Else
  104.             Output = Item & Main.QTY_SEPERATOR & List(Item)
  105.         End If
  106.  
  107.         ListRange.Value = ListRange.Value & Output
  108.         With ListRange.Characters(Start:=Position, Length:=Len(Output))
  109.             .Font.Color = RGB(0, 0, 0)
  110.             .Font.Bold = False
  111.         End With
  112.         Position = Position + Len(Item)
  113.     Next Item
  114.    
  115. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement