2017-03-08 8 views
0

私は隠したNamesを削除しようとしていますが、私は何を削除するかを選択するというルールで削除します。私は、ログシート上の名前 のリストを作るために管理し、私はそれの隣に1を入力したときに、私は名前を削除しないようにしたいという列を追加した、と私は空白のままにする場合、マイクロソフトのサポートからのコードを使用して選択によって非表示の名前を削除しようとしています

名前を削除したい。

ここに私のコードです:

Sub clean_names() 

Application.ScreenUpdating = False 
On Error Resume Next 

Set nms = ActiveWorkbook.Names 
MsgBox (nms.Count) 

For R = 1 To nms.Count 
    Name_Name = nms(R).Name 
    Name_Referance = nms(R).RefersTo 
    '###########ActiveWorkbook.Names(Name_Name).Delete 
    'ActiveWorkbook.nms(R).Delete 
    Sheets("LOG").Cells(R + 1, 1).Value = Name_Name 
    Sheets("LOG").Cells(R + 1, 2).Value = "'" + Name_Referance 
    'Application.StatusBar = R 
Next R 
'Application.StatusBar = False 
Application.ScreenUpdating = True 

End Sub 

'================================================================ 

Sub DelNames() 

Dim xName As Variant 
Dim Indx As Integer 
Dim Vis As Variant 

Cells(2, 1).Select 
If (ActiveCell = "") Then Exit Sub 
Indx = 1 

Do 
    If (ActiveCell.Offset(Indx, 2) = "") Then 

     xName = ActiveCell.Offset(Indx, 0).Value 
     If xName.Visible = True Then 
      Vis = "Visible" 
     Else 
      Vis = "Hidden" 
     End If 
     xName.Delete 
    End If 
    Indx = Indx + 1 
Loop While Len(ActiveCell.Offset(Indx, 0)) 

End Sub 

は、どのように私はこのコードを動作させることができますか?

答えて

0

以下のコードを試してみてください。これは列Aのすべての行をループし、列Cが空であるかどうかをチェックし、ブックからNameを削除します。

:私はNamesVisibleかそうでない場合は、あなたのポストによると、あなたが気にしないので、あなたが列Cの値に基づいて、それらを削除したい、あなたの元のコードから5行をコメントしました

コード

Option Explicit 

Sub DelNames() 

Dim xName   As Name 
Dim Indx   As Long 
Dim Vis    As Variant 
Dim LastRow   As Long 

With Worksheets("LOG") 
    If IsEmpty(.Range("A2").Value) Then Exit Sub 

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row '<-- get last row in column A (where you have a NamedRange) 
    For Indx = 2 To LastRow 
     If .Range("C" & Indx).Value = "" Then 
      ' set xName with the text entered in column A (as the Named Range Name) 
      Set xName = ThisWorkbook.Names(.Range("A" & Indx).Value) 

      ' not sure you need the 5 lines with the If criteria below so I Commented them for now 
      'If xName.Visible = True Then 
      ' Vis = "Visible" 
      'Else 
      ' Vis = "Hidden" 
      'End If 
      xName.Delete 
     End If 
    Next Indx 
End With 

End Sub 
+0

@Tal Kuceあなたは上記の私のコードを試してみましたか?それがあなたのために働いている場合は、「回答者」としてマークします。これはここでのことです。人々は質問をし、回答が得られると、「回答者」としてマーキングし、 –

関連する問題