Checkbox value

Solved
MF -  
 MF -
Hello,

I am really a novice on the topic of Excel Macros, but I will try to speak your language and be as clear as possible.

I have created checkboxes using form controls.
I would like that depending on the checked boxes, rows on another sheet of my workbook are visible (basically: if the box is not checked, hide the corresponding row).

My workbook:
- Sheet "Export" where the checkboxes are
- Sheet "Export recommendation" where the information to display or hide based on the checks is
- Animals: an example of one of the checkboxes that I renamed.

So I created this code (for the first checkbox only, I was thinking of copying and pasting for the following boxes):

Sheets("Export").Select
If Animals.Value = False Then
Sheets("Export recommendations").Select
Rows("8").Select
Selection.EntireRow.Hidden = True
End If

End Sub

With this code, I feel like my value is always considered false, and therefore my row 8 is always hidden.

Where could this problem be coming from?

Thank you very much for your help!

1 answer

Zoul67 Posted messages 2001 Status Member 149
 
Hello,

"Our" language?! French, of course...
In your code, you don't declare what happens if Animals.Value=True...

See you+
1
MF
 
Hello,

I also tried the code below, but with no better result:

If Animals = False Then
Sheets("Export recommendations").Select
Rows("8").Select
Selection.EntireRow.Hidden = True
Else
Sheets("Export recommendations").Select
Rows("8").Select
Selection.EntireRow.Hidden = False
End If

My value always seems to be considered as "False", whether my checkbox is checked or not.
0
Zoul67 Posted messages 2001 Status Member 149
 
Re,

Use an ActiveX control checkbox instead: it will initially be named CheckBox1.
To check that it handles the checked/unchecked toggles, I did:
Private Sub CheckBox1_Click() MsgBox CheckBox1.Value End Sub

Instead of using If, you can directly use the value of the CheckBox:
Private Sub CheckBox1_Click() Sheets("Feuil2").Rows("8").Hidden = CheckBox1.Value End Sub


With your object names, it should be:
Private Sub Animals_Click() Sheets("Export recommandations").Rows("8").Hidden = Animals.Value End Sub


A+
0
MF
 
Hello,

Thank you for your help which allowed me to fix my issue!
For your information, I also added a ThisWorkbook.Worksheets("Export") before the name of the CheckBox.

See you!
0