0
시트의 일부분 내에서 모든 명명 된 범위를 지우는 가장 좋은 방법은 무엇입니까? 같은지정된 범위 내에서 시트의 명명 된 범위를 지우시겠습니까?
뭔가 :
Sheets("A").Range("A1:D10").ClearNames
?
시트의 일부분 내에서 모든 명명 된 범위를 지우는 가장 좋은 방법은 무엇입니까? 같은지정된 범위 내에서 시트의 명명 된 범위를 지우시겠습니까?
뭔가 :
Sheets("A").Range("A1:D10").ClearNames
?
ClearNames에 대해 모르겠지만 이렇게하는 것이 좋습니다. 샘플 :이 트릭을 할해야 그 지역 내에서 이름을 제거하는 것을 의미
Option Explicit
Sub DeleteNamedRanges()
Dim targetWorksheet As Worksheet
Dim targetRange As Range
Dim nameObject As Name
Dim namedRange As Range
Dim unionedRange As Range
Set targetWorksheet = Worksheets("MySheetName")
Set targetRange = targetWorksheet.Range("A1:D10")
For Each nameObject In ActiveWorkbook.Names
Set namedRange = nameObject.refersToRange
If (namedRange.Worksheet.Name <> targetWorksheet.Name) Then GoTo Continue
Set unionedRange = Application.Union(namedRange, targetRange)
If (unionedRange.Address = targetRange.Address) Then
namedRange.Value = "" ' namedRange.Clear
End If
Continue:
Next nameObject
End Sub
경우, 단지 대상 지역에서 완전히 이름을하지 제거주의하시기 바랍니다. 따라서 A1과 D10의 내부와 외부에있는 범위도 삭제됩니다.
Option Explicit
Public Sub DeleteRangeNames()
Dim wsTarget As Worksheet
Dim rTarget As Range
Dim nTmp As Name
'Determine the range to clear all names from
Set wsTarget = Worksheets("enternamehere")
Set rTarget = wsTarget.Range("A1:D10")
'Loop through all Names in the worksheet
For Each nTmp In ActiveWorkbook.Names
'Check if they overlap (if no overlap the intersection is Nothing)
If Not (Intersect(nTmp.RefersToRange, rTarget) Is Nothing) Then
'Delete the Name object from the workbook
nTmp.Delete
End If
Next nTmp
End Sub
좋은 답변입니다. –