Get the value of a checkbox's linked cell...?

BuschMan

New Member
Joined
Jan 21, 2008
Messages
3
Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I am writing some VBA code in Excel 2007 and am stuck on a property with the standard form check box (not OLEObjects).<o:p></o:p>
<o:p></o:p>
I would like to check and find out what the value is of the linked cell for a checkbox...<o:p></o:p>
<o:p></o:p>
Like, if a user clicks the checkbox, it changes the linked cell value to true or false... But I cannot figure out how to "lookup" or "go and get" this true or false value through code...<o:p></o:p>
<o:p></o:p>
Anyone got any pointers on this one...?<o:p></o:p>
<o:p></o:p>
Thanks,<o:p></o:p>
"BuschMan"
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Under Format Control - the Control Tab enter into the Linked Cell reference box, Say B2

Then in your code the immediate window type:

? Range("B2").value
 
Upvote 0
You may want to try this :

Code:
MsgBox CBool(WorksheetFunction.Max(ActiveSheet.Shapes("Check Box 1").ControlFormat.Value, 0))

where ChecKbox1 is the name of the checkbox on the activesheet. change these as required.

Regards.
 
Upvote 0
Hi Guys,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Thanks for the quick reply...<o:p></o:p>
<o:p></o:p>
I am able to find out what the linked cell is, but cannot get the value... (See the code below)<o:p></o:p>
<o:p></o:p>
For example, is I change "Selection.LinkedCell" to "Selection.LinkedCell.Value" I get an error... Make sense...?<o:p></o:p>
<o:p></o:p>
Also, for reference, I also listed the code below that I am using to add the checkboxes to the document...<o:p></o:p>
<o:p></o:p>
Thanks,<o:p></o:p>
"BuschMan"<o:p></o:p>
<o:p></o:p>


Rich (BB code):
Sub CreateDocument()
 
Dim i As Integer
 
  For i = 2 To 6
 
  ActiveSheet.CheckBoxes.Add((Rows(i).Left) + 5, (Rows(i).Top + 5), 100, 25).LinkedCell = (Cells(i, 3).Address)
 
  Next i
 
End Sub



Rich (BB code):
Sub FindOutValue()<o:p></o:p>
<o:p></o:p>
Dim CB As Shape<o:p></o:p>
<o:p></o:p>
  For Each CB In ActiveSheet.Shapes<o:p></o:p>
<o:p></o:p>
      CB.Select<o:p></o:p>
<o:p></o:p>
      MsgBox Selection.LinkedCell<o:p></o:p>
<o:p></o:p>
  Next CB<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
 
Upvote 0
Try this :


Code:
Sub FindOutValue()
 
  Dim CB As CheckBox
 
  For Each CB In ActiveSheet.CheckBoxes
      MsgBox CBool(WorksheetFunction.Max(CB, 0))
  Next CB
 
End Sub
 
Upvote 0
Since the checkboxes are linked to the cell, you don't need to reference the cell as well as the control. Here are two syntax's you might use.
Code:
Dim CB As Object
For Each CB In ActiveSheet.Shapes
    MsgBox Range(CB.ControlFormat.LinkedCell).Value & " from cell"
    MsgBox CBool(CB.ControlFormat.Value And 1) & " from checkbox"
Next CB
 
Upvote 0
Hi Guys,

Thanks for the help... That worked perfect...!

So, now that I can figure out what the value of the linked cell is, how can I find out if the linked cell is visible or not...?

What I'm trying to do is have a checkbox for each row, and upon using the autofilter to hide some rows, I want to check to see if the linked cells are visible and if not, then hide the corresponsing checkboxes.

Let me know if anyone has any ideas on how to do this.

Thanks,
-"BuschMan"
 
Upvote 0
Code:
Dim CB As Object
For Each CB In ActiveSheet.Shapes
    With Range(CB.ControlFormat.LinkedCell)
        CB.Visible = Not (.EntireRow.Hidden Or .EntireColumn.Hidden)
    End With
Next CB
 
Last edited:
Upvote 0
In order to get mikerickson's code to run automatically when filtering the linked cells , I suggest that you add a formula with a SubTotal Function and place the code in the Worksheet Calculate Event handler.

For example:

Linked Cells : A1;A2;A3;A4 and A5 on Sheet1

in a remote cell on the sheet or better still, in a hidden sheet , place the following formula in a cell : =SUBTOTAL(9;Sheet1!$A$1:$A$5)

Then, place the code in the hidden sheet Calculate Event handler as follows :

Code:
Private Sub Worksheet_Calculate()
 
Dim CB As Object
For Each CB In Sheet1.Shapes
    With Sheet1.Range(CB.ControlFormat.LinkedCell)
        CB.Visible = Not (.EntireRow.Hidden Or .EntireColumn.Hidden)
    End With
Next CB
 
End Sub

Regards.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top