2017-04-11 6 views
1

こんにちは私はそれを実行すると、チェックボックスとコードがエラーを表示します。このエラーを修正してください。エラーのチェックボックスにプロパティを割り当てる方法

Private Sub CheckBox1_Click() 
    With Sheets("bom") 
     If .CheckBox1.Value = True Then 
      .Range("show_all_level") = "Yes" 
     Else 
      .Range("show_all_level") = "No" 
     End If 
    End With 
End Sub 

タイプ:

enter image description here

+1

おそらく、「show_all_level」という定義された範囲がありません。数式タブ>名前マネージャをチェックして、 "show_all_level"という定義された範囲があるかどうかを確認します。 –

+1

定義済みの範囲** show_all_level **は、チェックボックスと同じワークシートにありますか?つまり、ワークシート( "bom") – Jeeped

+0

さらに重要なのは、CheckBox1がシートbomにありますか? – sktneer

答えて

1

は、以下のコードを試してみてください、それはあなたがあなたの "show_all_level" Name Rangeを持っている可能性があるさまざまなシナリオを処理する必要があります。

Option Explicit 

Private Sub CheckBox1_Click() 

Dim Nm   As Name 
Dim NmExist  As Boolean 
Dim NameRng  As Range 

' loop through all Name Ranges in ThisWorkbook 
For Each Nm In ThisWorkbook.Names 
    If Nm.Parent.Name Like "bom" Then '<-- check if name range parent (Sheet.Name) is "bom" 
     MsgBox Nm.Name & " Name Range exists is sheet " & Chr(34) & Nm.Parent.Name & Chr(34) 
     NmExist = True ' raise the flag >> Name exist in "bom" sheet 
     Set NameRng = Nm.RefersToRange ' set the Range to the Name Range 
     Exit For 
    ElseIf Nm.Parent.CodeName Like "ThisWorkbook" Then '<-- check if name scope is "ThisWorkbook" 
     MsgBox Nm.Name & " Name Range exists as WorkBook scope" 
     NmExist = True ' raise the flag >> Name exist in Workbook scope 
     Set NameRng = Nm.RefersToRange ' set the Range to the Name Range 
     Exit For 
    End If 
Next Nm 

' verify that "show_all_level" name exist in "bom" sheet (or Workbook scope) 
If Not NmExist Then 
    MsgBox Chr(34) & "show_all_level" & Chr(34) & "Name Range, doesn't exist in the desired sheet", vbCritical 
    Exit Sub 
End If 

With Sheets("bom") 
    If .CheckBox1.Value = True Then 
     NameRng.Value = "Yes" 
    Else 
     NameRng.Value = "No" 
    End If 
End With 

End Sub 
+0

@DINESHKUMARPALANISAMYを参照してくださいhttps://meta.stackexchange.com/a/5235/289619 – 0m3r

+1

@ 0m3rこのリンクのおかげで;)私は過去に何度もそれを必要としている;) –

+0

SOコミュニティの仕組みを思い出させる良い方法 – 0m3r

関連する問題