R
RyanH
I have a CheckBox (chkShowTotal) in a cell on Sheets("QUOTE"). The code for
chkShowTotal is located in the Worksheet Module. The check box hides or
displays the Sub Total and TOTAL using comments. I have a Userform with a
button on it that executes a procedure and at the end of that procedure I
want to call the chkShowTotal_Click Procedure, but I am getting an error:
"Compile Error: Sub or Function not defined.", Why? Here is my code:
Private Sub cmbAddAsNew_Click()
' my userform code here
Call chkShowTotal_Click
End Sub
Public Sub chkShowTotal_Click()
Dim myTotal As Range
' applies the Sub Total on the QUOTE sheet
Set myTotal = ActiveSheet.Columns("G:G").Find(What:="TOTAL", _
After:=Cells(10, 7), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
ActiveSheet.Unprotect "AdTech"
' shows or hides Total and Sub Total, by using comments as storage
With myTotal
If chkShowTotal = True Then
.Offset(-3, 1).Formula = .Offset(-3, 1).Comment.Text
.Offset(-3, 1).Comment.Delete
.Offset(0, 1).Formula = .Offset(0, 1).Comment.Text
.Offset(0, 1).Comment.Delete
Else
.Offset(-3, 1).AddComment CStr(.Offset(-3, 1).Formula)
.Offset(-3, 1).ClearContents
.Offset(0, 1).AddComment CStr(.Offset(0, 1).Formula)
.Offset(0, 1).ClearContents
End If
End With
ActiveSheet.Protect "AdTech"
End Sub
chkShowTotal is located in the Worksheet Module. The check box hides or
displays the Sub Total and TOTAL using comments. I have a Userform with a
button on it that executes a procedure and at the end of that procedure I
want to call the chkShowTotal_Click Procedure, but I am getting an error:
"Compile Error: Sub or Function not defined.", Why? Here is my code:
Private Sub cmbAddAsNew_Click()
' my userform code here
Call chkShowTotal_Click
End Sub
Public Sub chkShowTotal_Click()
Dim myTotal As Range
' applies the Sub Total on the QUOTE sheet
Set myTotal = ActiveSheet.Columns("G:G").Find(What:="TOTAL", _
After:=Cells(10, 7), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
ActiveSheet.Unprotect "AdTech"
' shows or hides Total and Sub Total, by using comments as storage
With myTotal
If chkShowTotal = True Then
.Offset(-3, 1).Formula = .Offset(-3, 1).Comment.Text
.Offset(-3, 1).Comment.Delete
.Offset(0, 1).Formula = .Offset(0, 1).Comment.Text
.Offset(0, 1).Comment.Delete
Else
.Offset(-3, 1).AddComment CStr(.Offset(-3, 1).Formula)
.Offset(-3, 1).ClearContents
.Offset(0, 1).AddComment CStr(.Offset(0, 1).Formula)
.Offset(0, 1).ClearContents
End If
End With
ActiveSheet.Protect "AdTech"
End Sub