突出显示行,如果上面的活动单元格匹配底部。

huangapple go评论71阅读模式
英文:

Highlight the row if the above active cell matches the bottom

问题

Here's the translated code part:

子重复颜色()
     Dim i As Long, cIndex As Long
     cIndex = 3
     Cells(1, 1).Interior.ColorIndex = cIndex
     For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(i, 1) = Cells(i + 1, 1) Then
           Cells(i + 1, 1).Interior.ColorIndex = cIndex
       Else
           If Cells(i + 1, 1) <> "" Then
               cIndex = cIndex + 1
               Cells(i + 1, 1).Interior.ColorIndex = cIndex
           End If
       End If
   Next i
End Sub

If you need further assistance or have any questions, please let me know.

英文:
Sub dupColors()
     Dim i As Long, cIndex As Long
     cIndex = 3
     Cells(1, 1).Interior.ColorIndex = cIndex
     For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(i, 1) = Cells(i + 1, 1) Then
           Cells(i + 1, 1).Interior.ColorIndex = cIndex
       Else
           If Cells(i + 1, 1) &lt;&gt; &quot;&quot; Then
               cIndex = cIndex + 1
               Cells(i + 1, 1).Interior.ColorIndex = cIndex
           End If
       End If
   Next i
End Sub

I got rid of cIndex, not needed. Basically I want to highlight groups of CUSIP numbers which are always different and the data range is dynamic. The way i go about it is by sorting the cusip datarange so that they are all grouped.

I need a script that would highlight each group then alternate to another color when they do not match. The issue is that the cell numbers can jump and therefore any i+1 functions do not work. Any ideas?

Regards

I tried an if function where it first states the range then does a count up to see the last cell that was input. From there the function would jump up (i + 1) and highlight if it was the same string. If not it would go to the next.

答案1

得分: 2

以下是翻译好的代码部分:

Sub dupColors()
    Dim i As Long, n As Long, arrColors, currVal, v
    
    arrColors = Array(24, 40) '或其他值
    currVal = Chr(0) '非值
    For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        v = Cells(i, 1)
        If v <> currVal Then
            currVal = v
            n = n + 1
        End If
        ' n Mod 2 将为 0 或 1...
        Cells(i, 1).Interior.ColorIndex = arrColors(n Mod 2)
    Next i
End Sub

如果您需要进一步的帮助,请随时提问。

英文:

Try this out:

Sub dupColors()
    Dim i As Long, n As Long, arrColors, currVal, v
    
    arrColors = Array(24, 40) &#39;or whatever
    currVal = Chr(0) &#39;non-value
    For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        v = Cells(i, 1)
        If v &lt;&gt; currVal Then
            currVal = v
            n = n + 1
        End If
        &#39; n Mod 2 will be 0 or 1...
        Cells(i, 1).Interior.ColorIndex = arrColors(n Mod 2)
    Next i
End Sub

huangapple
  • 本文由 发表于 2023年6月9日 07:06:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436229.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定