在具有相同值的单元格周围创建边框
我有一张如下所示的表格。我怎样才能让Excel在第4列中放置具有相同编号的组的边框,以便围绕组存在边框。我正在考虑条件格式可以做到这一点,但我想不出如何。所以我认为唯一的选择是宏观。任何人都可以帮忙吗?在具有相同值的单元格周围创建边框
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
您需要使用相对引用。
- 选择您想要进行条件格式化的列范围。
- 在自己的情况输入以下三个公式:
- = AND($ C2 = $ C3,C3 $ = $ C4)
- 这一个是对中间项。 (在两侧上边框)
- = AND($ C2 <> $ C3,C3 $ = $ C4)
- 这一个是该组中的第一个。 (上左,上边界,右)
- = AND($ C2 = $ C3,C3 $ <> $ C4)
- 这一个是最后在组中。 (左,下边框,右)
- = AND($ C2 = $ C3,C3 $ = $ C4)
- 格式如您所愿。
将'$ C'全部替换为'$ {Your Column}'。请注意,这不会在单个项目周围放置任何边框,因为您可以在选区中不再有三个条件格式条件。
我推出了这个解决方案,它在我的Excel 2010上很奇怪:/ 我无法在2003年测试它,所以请让我知道如果这很好。
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
你只是想让人眼更易读吗?如果是这样,我建议交替的背景颜色。例如,每当第四列中的数字发生变化时,背景颜色将从白色变为蓝色,反之亦然。我此做所有的时间:
使一个附加列E.由于参考列是d,输入:
= MOD(IF(D5 <> D4,E4 + 1,E4),2 )
(即,如果该行的列d是从最后一行的d不同,则改变从0至1或1至0)隐藏列,以便最终用户不会看到它。
制作2个条件公式。如果您的隐藏值为0,则第一个会将行颜色更改为白色。如果您的隐藏值为1,则第二个会将其更改为蓝色。
没有宏。没有VBA编码。只有1个隐藏的列和一些条件公式。而且颜色还是应交替正常,即使你的列d被跳过数:)
(我用这个每天在2003 XL我希望它可以在2007年)
我不能看到一个简单的非宏解决方案正是你需要的,但PowerUser的解决方案似乎没问题。
这是一个基于宏的解决方案,它将在最后一列中具有相同数字的行放置一个边框。我会假设你的数据在A:D列中。
要使用此宏,只需单击列表中的任意单元格,然后触发宏。
用作快速指南:
-
AddBorders
是简单地通过在最后一列的所有单元格循环和作品出主宏时边框是适当 -
AddBorder
是一个简短的程序,增加了边境。 -
作为奖励,
AddBorder
选择从Excel的56调色板随机颜色,使每个边界都不同的颜色,使便于观看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
参见https://superuser.com/问题/ 524678/excel-how-to-conditional-format-a-thick-bottom-border-to-an-whole-row-based-on和https://www.extendoffice.com/documents/excel/4046- Excel的附加边界时,价值changes.html – 2017-06-01 13:08:56