I have a quick question about checkboxes. I am trying to change the values of checkboxes on a tab using VBA. I have one piece of code working that triggers when certain cells change, and updates the value of the checkbox accordingly. this code is located on the worksheet. i have another section of code located in a module that does not work. In both instances, i am referring to my checkboxes as me.CbName. do i need to refer to them differently when i have my code stored in a module?
This code does not work (stored in a module)
This is the code that works (stored on the worksheet)
This code does not work (stored in a module)
Code:
Sub deleteme()
Dim xyz As Boolean
xyz = True
If xyz = True Then Me.CBRates = True
End Sub
This is the code that works (stored on the worksheet)
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("C4:E50")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
'MsgBox "Cell " & Target.Address & " has changed."
If Target.Address = "$C$4" Then
ElseIf Target.Address = "$C$5" Then
'Census Views?
If Target.Value = "Yes" Then
Sheets("Census").Visible = True
Me.CbCensus = True
Else
Sheets("Census").Visible = False
Me.CbCensus = False
Call ImportScript
Call ShowRow
Call ShowCol
'MsgBox "Be Sure to Import the Census"
End If
ElseIf Target.Address = "$C$6" Then
If Sheets("Case Info").Range("C6").Value = "No" And Sheets("Case Info").Range("C7").Value = "No" Then
Sheets("Current Benefits").Visible = False
Me.CBCurrentBen = False
Else
Sheets("Current Benefits").Visible = True
Me.CBCurrentBen = True
End If
ElseIf Target.Address = "$C$7" Then
If Sheets("Case Info").Range("C6").Value = "No" And Sheets("Case Info").Range("C7").Value = "No" Then
Sheets("Current Benefits").Visible = False
Me.CBCurrentBen = False
Else
Sheets("Current Benefits").Visible = True
Me.CBCurrentBen = True
End If
ElseIf Target.Address = "$C$8" Then
'Are there custom plans?
If Target.Value = "Yes" Then
Sheets("Custom Benefit Request").Visible = True
Me.CBCustom = True
'MsgBox "Be Sure to Import the Census"
Else
Sheets("Custom Benefit Request").Visible = False
Me.CBCustom = False
ImportScript
End If
ElseIf Target.Address = "$E$8" Then
'How Many?
ShowColCustom
ElseIf Target.Address = "$C$39" Then
If Target.Value = "Commission" Then
Rows("40:42").EntireRow.Hidden = False
ElseIf Target.Value = "PSF" Then
Rows("40:41").EntireRow.Hidden = False
Rows("42:42").EntireRow.Hidden = True
Else
Rows("40:42").EntireRow.Hidden = True
End If
ElseIf Target.Address = "$C$43" Then
If Target.Value = "Yes" Then
Rows("44:48").EntireRow.Hidden = False
Else
Rows("44:48").EntireRow.Hidden = True
End If
End If
End If
End Sub