在具有相同值的单元格周围创build边框

我有一张桌子,就像下面这张桌子一样。 我怎样才能让Excel在第四列中放置相同编号的边框,以便在这些组周围有一个边框。 我正在考虑条件格式可以做到这一点,但我不知道如何。 所以我认为唯一的select是一个macros。 有人可以帮忙吗?

1 64436 549419 1 2 64437 549420 1 3 64438 549421 1 4 64439 549422 1 5 64440 549423 1 6 64441 549424 1 7 64442 549425 1 8 64443 549426 1 9 64444 549427 1 10 64445 549428 1 11 64446 549429 1 12 64447 549430 1 13 64448 549431 2 14 64449 549432 2 15 64450 549433 2 16 64451 549434 2 17 64452 549435 2 18 64453 549436 2 19 64454 549437 2 20 64455 549438 2 21 64456 549439 2 22 64457 549440 4 23 64458 549441 4 24 64459 549442 5 25 64460 549443 5 26 64461 549444 5 27 64462 549445 5 28 64463 549446 5 29 64464 549447 5 30 64465 549448 6 31 64466 549449 6 32 64467 549450 6 33 64468 549451 6 34 64469 549452 6 35 64470 549453 6 36 64471 549454 6 37 64472 549455 9 38 64473 549456 9 39 64474 549457 9 

您需要使用相对引用。

  1. select您想要进行条件格式化的列范围。
  2. 在他们自己的条件下input以下三个公式:
    • = AND($ C2 = $ C3,C3 $ = $ C4)
      • 这是一个中间项目。 (双方边界)
    • = AND($ C2 <> $ C3,C3 $ = $ C4)
      • 这是一个在小组中的第一个。 (左边,上边,右边的边框)
    • = AND($ C2 = $ C3,C3 $ <> $ C4)
      • 这一个是在组中的最后一个。 (左边,底部,右边的边框)
  3. 格式化他们,你想要的。

将“$ C”全部replace为“$ {Your Column}”。 请注意,这不会在单个项目周围放置任何边框,因为您可以在select中不再有三个条件格式条件。

我看不到一个简单的非macros观解决scheme,正是你所需要的,但PowerUser的解决scheme似乎没问题。

这是一个基于macros的解决scheme,将在最后一列中具有相同数字的行放置一个边框。 我将假设你的数据在A:D列。

要使用这个macros,只需单击列表中的任何单元格,然后触发macros。

作为快速指南:

  • AddBorders是简单循环遍历最后一列中的所有单元格的主要macros,并在边界合适时执行
  • AddBorder是添加边框的简短例程。
  • 作为奖励, AddBorder从Excel的56调色板中select一个随机颜色,以便每个边框都是不同的颜色,以便于查看

     Sub AddBorders() Dim startRow As Integer Dim iRow As Integer startRow = 1 For iRow = 2 To ActiveCell.CurrentRegion.Rows.Count If WorksheetFunction.IsNumber(Cells(iRow + 1, 4)) Then If Cells(iRow, 4) <> Cells(iRow - 1, 4) Then AddBorder startRow, iRow - 1 startRow = iRow End If Else AddBorder startRow, iRow End If Next iRow End Sub Sub AddBorder(startRow As Integer, endRow As Integer) Dim borderRange As Range Dim randomColor As Integer randomColor = Int((56 * Rnd) + 1) Set borderRange = Range("A" & startRow & ":D" & endRow) borderRange.BorderAround ColorIndex:=randomColor, Weight:=xlThick End Sub 

我出来这个解决scheme,它在我的Excel 2010奇怪的工作︰/我无法在2003年testing,所以请让我知道如果这很好。

 Sub PaintBorder() Dim iRow As Integer iRow = 1 Dim strTemp As String strTemp = Range("D" & iRow).Value Dim strPrev As String Dim sectionStart As Integer sectionStart = 1 Do strPrev = strTemp strTemp = Range("D" & iRow).Value If strPrev <> strTemp Then ActiveSheet.Range(Cells(sectionStart, 1), Cells(iRow - 1, 4)).BorderAround xlSolid, xlMedium, xlColorIndexAutomatic sectionStart = iRow End If iRow = iRow + 1 Loop Until strTemp = vbNullString End Sub 

你只是想让人眼更易读吗? 如果是这样,我build议交替的背景颜色。 例如,每当第四列中的数字改变时,背景颜色将从白色变为蓝色,反之亦然。 我一直这样做:

  1. 增加一列E.由于您的参考列是D,请input:
    = MOD(IF(D5 <> D4,E4 + 1,E4),2)
    (即,如果该行的列D不同于最后一行的D,则从0更改为1或1更改为0)

  2. 隐藏该列,以便最终用户不会看到它。

  3. 做2个条件公式。 如果你的隐藏值是0,第一个将把行的颜色改成白色。如果你的隐藏值是1,第二个将把它改变成蓝色。

没有macros。 没有VBA编码。 只有1个隐藏的列和一些条件公式。 即使您的列D跳过数字,颜色仍然应该正确交替:)

(我在XL 2​​003上每天使用这个function,希望它能在2007年使用)