Checkbox Loose Value when Closing sheet

Rocksie

New Member
Joined
May 17, 2017
Messages
26
Hi All,

I need some help please. I have active X checkboxes on a form which when unchecked (the default is checked) will hide certain rows based a the value in a cell in column "L".

My problem is when I close the form with the "X" on top or when I save the file and re-open it, the checkbox looses its value, i.e when it was unchecked before, it will be checked when opening the file again, BUT the rows will still be hidden which creates problems...

Any ideas how to overcome that?

Thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
The following example will store all checkbox values as names, then restore when form is re-initialized.

Code:
[/COLOR][COLOR=#333333]Private Sub cmd_Save_Click()[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">  For Each ct In Controls
    If TypeName(ct) = "CheckBox" Then ThisWorkbook.Names.Add ct.Name, ct
  Next

  Unload
End Sub

Private Sub UserForm_Initialize()
  On Error Resume Next
  For Each ct In Controls
    If TypeName(ct) = "CheckBox" Then ct.Value = ThisWorkbook.Names(ct.Name).RefersTo = "=TRUE"
  Next </code>[COLOR=#333333]End Sub[/COLOR][COLOR=#333333]

 
Upvote 0
Thanks Jonathann, I'll try it.

Do I put it in the worksheet module or in the Userform module?
 
Upvote 0
Userform controls lose their value when the form is closed.
But, since these checkboxes are linked to the visibility of rows, you could write your initialize event to look at those rows and determine which of the checkboxes should be checked.
 
Upvote 0
Thank you all for the advice. I've added a very hidden sheet to the workbook to which the checkbox reads a value, that solved my problem
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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