Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim dataRange As Range
Dim v As Variant, I As Long
Set dataRange = Range(Cells(2, 2), Cells(100, 10)) 'change as needed
If Not Intersect(Target, dataRange) Is Nothing Then
With dataRange
v = .Columns(9)
For I = 1 To UBound(v) - 1
If v(I, 1) <> v(I + 1, 1) Then
With .Rows(I).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = vbBlack
.Weight = xlThick
End With
Else
.Rows(I).Borders(xlEdgeBottom).LineStyle = xlNone 'or whatever you want for the default border
End If
Next I
End With
End If
End Sub
Option Explicit
Sub LineIT()
Dim WS As Worksheet
Dim dataRange As Range
Dim v As Variant, I As Long
Set WS = ThisWorkbook.Worksheets("Sheet4") 'or whatever workbook and worksheet the table you which to process is located
With WS
Set dataRange = Range(.Cells(2, 1), Cells(.Rows.Count, 10).End(xlUp)) 'change as needed
With dataRange
v = .Columns(10)
For I = 1 To UBound(v) - 1
If v(I, 1) <> v(I + 1, 1) Then
With .Rows(I).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Color = vbBlack
.Weight = xlThick
End With
Else
.Rows(I).Borders(xlEdgeBottom).LineStyle = xlNone 'or whatever you want for the default border
End If
Next I
End With
End With
End Sub
这可以通过条件格式轻松完成。
Use Formula for Conditional Formatting
=$J2<>$J1
并根据需要设置边框Applies To
单元格以使下划线转到您想要的单元格如果您对黑色细边框没问题,那么条件格式将起作用。如果你真的想要一个粗黑色边框,你将需要 VBA 事件代码,因为你不能在条件格式边框属性中修改边框的粗细。
要输入此事件触发的宏,请右键单击工作表选项卡。从右键单击下拉菜单中选择“查看代码”。然后将下面的代码粘贴到打开的窗口中。
编辑:要让一个独立的而不是事件触发的宏
进入常规模块
,然后您可以从另一个宏调用它,或者使用按钮触发它,或者手动启动它