Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim cell As Range
' Check if any cell in column A is modified
If Not Intersect(Target, Range("A:A")) Is Nothing Then
' Set the range from the modified cell in column A to column D
Set rng = Range(Target, Cells(Target.Row, "D"))
' Remove existing borders if the corresponding cell is empty
If IsEmpty(Target) Then
rng.Borders.LineStyle = xlNone
Else
' Add new borders to each cell
For Each cell In rng
With cell.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With cell.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With cell.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With cell.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
End With
Next cell
End If
End If
End Sub
我希望即使我一次删除多个单元格的值,边框也应该自动删除。
2条答案
按热度按时间h9vpoimq1#
您可以使用以下结构作为模板,用相关代码替换注解行:
mzsu5hc02#
使用下面的代码,您可以同时粘贴多个值,也可以一次删除多个单元格。在粘贴过程中,某些单元格可能会增加值,而其他单元格可能会丢失值...