突出显示重复的列对并计算行Excel


-1

给定下面的数据,应突出显示至少连续4行具有相同值的列对。

这是一个 图像更好的可视化

2   2
3   4
3   4
3   4
3   4
2   3
1   2
2   2
3   3
3   3
3   3
3   3
2   3
2   3
2   3
2   3
2   2
3   4
3   4
3   4
3   4
3   4

输出应该是这样的,其中突出显示至少4个连续行相同的列对值:

2   2
3   4
3   4
3   4
3   4
2   3
1   2
2   2
3   3
3   3
3   3
3   3
2   3
2   3
2   3
2   3
2   2
3   4
3   4
3   4
3   4
3   4

然后,我需要知道N连续相等列对的实例数。考虑到上述数据,N = 4应为3,N = 5应为1,其中N是列对连续相等的行数。


1
原样,这不是一个真正的问题。你已经尝试了什么,你在哪里被困?请编辑您的问题以包含该信息。
Ƭᴇcʜιᴇ007

啊,这个看起来很像你以前的问题。虽然它有点不同。我决定保持开放,但请包含有关您已有的信息。
slhck

这听起来有点复杂,只是使用条件格式,我怀疑它需要一个适当的宏来编写它做得很好。正如技术人员所说,到目前为止你尝试了什么?
Mokubai

Answers:


0

正如我在评论中提到的,我认为这有点超出了条件格式的能力。

因此,我提交您的细读以下Excel宏来转变这一点

Before

进入这个

After

我对此数据不承担任何责任。它 需要微调你的情况(行和列开始数字等),如果它创建一个黑洞,你的计算机消失了一阵 某物 那么我要说的就是“哇,你有没有在相机上得到它?”因为那会很棒。

也就是说,它对我有用,如果你设置正确,它也适合你。或者您可以修改它以更好地满足您的需求。

Sub RepeatedRows()
'Written by Mokubai, 14/10/12
FirstColumn = "A"
LastColumn = "B"
StartRow = 2

' First we establish how far we are going down the table
NumRows = ActiveSheet.UsedRange.Rows.Count
NumCols = ActiveSheet.UsedRange.Columns.Count

'Then we start working out
RowString = ""
oldRowString = ""
numRepeated = 0

For i = StartRow To NumRows
    FirstCell = FirstColumn & i
    'FirstCell = "A1"
    LastCell = LastColumn & i
    'Create a temporary string that is the row contents
    For Each Cell In Range(FirstCell, LastCell)
        RowString = RowString & Cell.Value
    Next Cell
    'compare it to the previous row:
    If RowString = oldRowString Then
        numInGroup = numInGroup + 1
    Else
        numInGroup = 0
        Range(FirstCell).EntireRow.Interior.ColorIndex = 0
    End If

    'now we fill in the current and all previous rows to the same colour
    'I have done absolutely nothing facy with the colouring, it is simply using the value
    For col = 0 To numInGroup
        CellNo = FirstColumn & (i - col)
        Range(CellNo).EntireRow.Interior.ColorIndex = (numInGroup)

        'this next bit is so that only the last member of the group gets a value in it
        'in order to help define where the groups are
        EmptyColumn = "C" & i - col
        Range(EmptyColumn).Select
        If col = 0 Then
            ActiveCell.Value = numInGroup + 1
        Else
            ActiveCell.Value = ""
        End If
    Next col

    'in either case we store the current row string and clear the temporary row string and repeat
    oldRowString = RowString
    RowString = ""
Next

End Sub
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.