Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Macro1()
  2. '
  3. ' Macro1 Macro
  4. '
  5. '
  6. Dim runningTotal As Range
  7. Dim runTotCounter As Integer
  8. Dim subRangeCounter As Integer
  9. Dim subRange0 As Range
  10. Dim subRange1 As Range
  11. Dim subRange2 As Range
  12. Dim subRange3 As Range
  13. Dim subRange4 As Range
  14. Dim subRange5 As Range
  15. Dim subRange6 As Range
  16. Dim subRange7 As Range
  17.  
  18.  
  19. subRangeCounter = 0
  20. reference = Range("A4").Value
  21.  
  22. ThisWorkbook.Sheets(7).Range("A:JL").FormatConditions.Delete ' Delete current scales
  23.  
  24. For Each c In Worksheets("PVP Calculator").Range("A7:JL1506").Cells
  25.  '   If c.Interior.colorIndex <> 0 Then
  26.  '      c.Interior.colorIndex = 0
  27.   ' End If
  28.    If c.Value >= reference - 5 And c.Value <= reference Then
  29.  '       c.Interior.colorIndex = 6
  30.        If runningTotal Is Nothing Then
  31.             Set runningTotal = c
  32.         Else
  33.             Set runningTotal = Union(runningTotal, c)
  34.         End If
  35.         runTotCounter = runTotCounter + 1
  36.         If runTotCounter > 200 Then
  37.             runTotCounter = 0
  38.             If subRangeCounter = 0 Then
  39.                 Set subRange0 = runningTotal
  40.             End If
  41.             If subRangeCounter = 1 Then
  42.                 Set subRange1 = runningTotal
  43.             End If
  44.             If subRangeCounter = 2 Then
  45.                 Set subRange2 = runningTotal
  46.             End If
  47.             If subRangeCounter = 3 Then
  48.                 Set subRange3 = runningTotal
  49.             End If
  50.             If subRangeCounter = 4 Then
  51.                 Set subRange4 = runningTotal
  52.             End If
  53.             If subRangeCounter = 5 Then
  54.                 Set subRange5 = runningTotal
  55.             End If
  56.             If subRangeCounter = 6 Then
  57.                 Set subRange6 = runningTotal
  58.             End If
  59.             If subRangeCounter = 7 Then
  60.                 Set subRange7 = runningTotal
  61.             End If
  62.             Set runningTotal = ""
  63.             MsgBox ("made it")
  64.             subRangeCounter = subRangeCounter + 1
  65.         End If
  66.     End If
  67. Next
  68. MsgBox (runTotCounter)
  69. If subRangeCounter = 0 And runningTotal Is Nothing Then
  70.     Set runningTotal = Range("JL1506") ' We're gonna do a little something something where the max possible stat is used if we can't get to 1500
  71. End If
  72.  
  73. ' We delete the existing names, in a troubleshooting attempt to figure out why a second run through resulted in an error for the line below
  74.  
  75. runningTotal.Name = "runTot"
  76. If Not subRange0 Is Nothing Then
  77.     subRange0.Name = "sub0"
  78. End If
  79. If Not subRange1 Is Nothing Then
  80.     subRange1.Name = "sub1"
  81. End If
  82. If Not subRange2 Is Nothing Then
  83.     subRange2.Name = "sub2"
  84. End If
  85. If Not subRange3 Is Nothing Then
  86.     subRange3.Name = "sub3"
  87. End If
  88. If Not subRange4 Is Nothing Then
  89.     subRange4.Name = "sub4"
  90. End If
  91. If Not subRange5 Is Nothing Then
  92.     subRange5.Name = "sub5"
  93. End If
  94. If Not subRange6 Is Nothing Then
  95.     subRange6.Name = "sub6"
  96. End If
  97. If Not subRange7 Is Nothing Then
  98.     subRange7.Name = "sub7"
  99. End If
  100.  
  101. If subRangeCounter = 0 Then
  102.     Set master = runningTotal
  103. End If
  104. If subRangeCounter = 1 Then ' remember the counter has gone up by 1 more than a "filled" subRange
  105.    Set master = Union(runningTotal, subRange0)
  106. End If
  107. If subRangeCounter = 2 Then
  108.     Set master = Union(runningTotal, subRange0, subRange1)
  109. End If
  110. If subRangeCounter = 3 Then
  111.     Set master = Union(runningTotal, subRange0, subRange1, subRange2)
  112. End If
  113. If subRangeCounter = 4 Then
  114.     Set master = Union(runningTotal, subRange0, subRange1, subRange2, subRange3)
  115. End If
  116. If subRangeCounter = 5 Then
  117.     Set master = Union(runningTotal, subRange0, subRange1, subRange2, subRange3, subRange4)
  118. End If
  119. If subRangeCounter = 6 Then
  120.     Set master = Union(runningTotal, subRange0, subRange1, subRange2, subRange3, subRange4, subRange5)
  121. End If
  122. If subRangeCounter = 7 Then
  123.     Set master = Union(runningTotal, subRange0, subRange1, subRange2, subRange3, subRange4, subRange5, subRange6)
  124. End If
  125. If subRangeCounter = 8 Then
  126.     Set master = Union(runningTotal, subRange0, subRange1, subRange2, subRange3, subRange4, subRange5, subRange6, subRange7)
  127. End If
  128.  
  129. master.Name = "master"
  130.  
  131. Range("master").Select
  132.  
  133. ' I took out the gradient because it was broken when I added in a tolerance to the target ranges.
  134.  
  135. ' This highlights every other applicable cell on a gradient
  136. '    Selection.FormatConditions.AddColorScale ColorScaleType:=2
  137. '    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
  138. '    Selection.FormatConditions(1).ColorScaleCriteria(1).Type = _
  139. '        xlConditionValueLowestValue
  140. '    With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
  141. '        .Color = 16776444
  142. '        .TintAndShade = 0
  143. '    End With
  144. '    Selection.FormatConditions(1).ColorScaleCriteria(2).Type = _
  145. '        xlConditionValueHighestValue
  146. '    With Selection.FormatConditions(1).ColorScaleCriteria(2).FormatColor
  147. '        .Color = 8109667
  148. '        .TintAndShade = 0
  149. '    End With
  150.    
  151.  ' Then add the #1 formatting, which is Bold and Gold; apparently what is added last is the highest priority
  152.    Selection.FormatConditions.AddTop10
  153.     Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
  154.     With Selection.FormatConditions(1)
  155.         .TopBottom = xlTop10Top
  156.         .Rank = 1
  157.         .Percent = False
  158.     End With
  159.     With Selection.FormatConditions(1).Font
  160.         .Bold = True
  161.         .Italic = False
  162.  '       .TintAndShade = 0 ' Damn thing keeps throwing errors despite being sourced from macro recorder
  163.    End With
  164.     With Selection.FormatConditions(1).Interior
  165.         .PatternColorIndex = xlAutomatic
  166.         .Color = 49407
  167.         .TintAndShade = 0
  168.     End With
  169.     Selection.FormatConditions(1).StopIfTrue = False
  170.  
  171. 'Range("L3").formula = "=Max(" & runningTotal.Address & ")"
  172. ' But using a name range, I get this perk
  173. Range("L3").formula = "=MAX(master)"
  174. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement