Private Sub Worksheet_Change(ByVal Target As Range)
Dim xRng As Range
On Error Resume Next
Set xRng = Sheets("Sheet1").Range("XXXX") '檢測定義名稱(Sheet1)是否有效
If Not xRng Is Nothing Then Exit Sub '若XXXX定義名稱還有效, 表示不是刪除, 跳出
Set xRng = Sheets("Sheet2").Range("YYYY") '檢測定義名稱(Sheet2)是否有效
On Error GoTo 0
If Not xRng Is Nothing Then xRng.EntireRow.Delete '同步刪除Sheet2的YYYY位址列
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
ThisWorkbook.Names("XXXX").Delete '刪除定義名稱
ThisWorkbook.Names("YYYY").Delete '刪除定義名稱
On Error GoTo 0
With Target
If .Columns.Count <> Columns.Count Then Exit Sub '非選取[整列]跳出
.Cells.Name = "XXXX" '定義名稱(Sheet1)
Sheets("Sheet2").Range(.Address).Name = "YYYY" '定義名稱(Sheet2)
End With
End Sub作者: li_hsien 時間: 2019-2-15 14:40