Alex Simmons
New Member
- Joined
- Dec 3, 2012
- Messages
- 17
I'm trying to sort out my checkbox logic - but what I have isn't doing what I expect.
what I'm attempting to do is have:
this way, when they reopen the same userform later, the previously set values are shown in the checkboxes.
My final intent is to provide the user with a way to select which named ranges of the workbook to print-preview but recognise that they will most often just want to use the setting they previously chose, and not require them to reselect the pages to preview each time.
Sheet attached (ah, no it's not - I thought I could attach my sheet?).
This is the code I have for the userform and checkboxes.
What am I doing wrong?
thanks!
what I'm attempting to do is have:
- a userform with checkboxes (say 2 checkboxes in this example)
- the checkboxes to auto-populate with True/False based on the pre-existing values in cells A1, A2 of Sheet1
- the user then can change the selection in the checkboxes on the userform, which then updates the values in cells A1, A2
this way, when they reopen the same userform later, the previously set values are shown in the checkboxes.
My final intent is to provide the user with a way to select which named ranges of the workbook to print-preview but recognise that they will most often just want to use the setting they previously chose, and not require them to reselect the pages to preview each time.
Sheet attached (ah, no it's not - I thought I could attach my sheet?).
This is the code I have for the userform and checkboxes.
What am I doing wrong?
thanks!
Code:
Private Sub UserForm_Activate()
' when opening the userform set the checkboxes on
' userform to show the values stored in cells A1 & A2
CheckBox1.Value = Sheets("Sheet1").Range("A1").Value
CheckBox2.Value = Sheets("Sheet1").Range("A2").Value
' however for some reason this is toggling the cell
' values instead of displaying what was previously there
' I just want it to show what's already in the cells
' and not change their value
End Sub
Private Sub CheckBox1_Change()
' when user changes checkbox1 value on userform
' then toggle the stored (true/false) value in cell A1
If Sheets("Sheet1").Range("A1").Value = True _
Then Sheets("Sheet1").Range("A1").Value = False _
Else Sheets("Sheet1").Range("A1").Value = True
' what this is doing is toggling the value in cell A1, but the
' checkbox displays a value opposite to that stored in the cell.
' A TRUE is cell A1 shows on the checkbox as not checked, and
' a FALSE in cell A1 shows on the checkbox as checked.
End Sub
Private Sub CheckBox2_Change()
' same as for checkbox1 and cell A1
If Sheets("Sheet1").Range("A2").Value = True _
Then Sheets("Sheet1").Range("A2").Value = False _
Else Sheets("Sheet1").Range("A2").Value = True
End Sub