when select cell in range checkbox value is true_but how?

U

up2you

Hi all,

I have 3 checkbox in sheet and i have 3 range name x, y and z.

what i want is,

when i *select any cell in x range checkbox1.value=true *is run,
when i *select any cell in y range checkbox2.value=true *is run,
when i *select any cell in z range checkbox3.value=true * is run.

what is the code for this operations?

thanks.....
 
A

Ardus Petus

With your 3 ranges named "sel_X", "sel_Y" and "sel_Z",
paste following code in worksheet's code:

'-----------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
CheckBox1.Value = _
Not Intersect(Range("sel_X"), Target) Is Nothing
CheckBox2.Value = _
Not Intersect(Range("sel_Y"), Target) Is Nothing
CheckBox3.Value = _
Not Intersect(Range("sel_Z"), Target) Is Nothing
End Sub
'------------------

HTH
 
C

cm_gmail

To snag a snippet of code from here:
http://www.cpearson.com/excel/named.htm

You can do this:

Code:
--------------------
Function NameOfParentRange(Rng As Range) As String
Dim Nm As Name
For Each Nm In ThisWorkbook.Names
If Rng.Parent.Name = Nm.RefersToRange.Parent.Name Then
If Not Application.Intersect(Rng, Nm.RefersToRange) Is Nothing Then
NameOfParentRange = Nm.Name
Exit Function
End If
End If
Next Nm
NameOfParentRange = ""
End Function

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells(1, 1).Value = NameOfParentRange(Target)
End Sub
 
C

cm_gmail

To snag a snippet of code from here:
http://www.cpearson.com/excel/named.htm

You can do this:

Code:
--------------------
Function NameOfParentRange(Rng As Range) As String
Dim Nm As Name
For Each Nm In ThisWorkbook.Names
If Rng.Parent.Name = Nm.RefersToRange.Parent.Name Then
If Not Application.Intersect(Rng, Nm.RefersToRange) Is Nothing Then
NameOfParentRange = Nm.Name
Exit Function
End If
End If
Next Nm
NameOfParentRange = ""
End Function

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells(1, 1).Value = NameOfParentRange(Target)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top