Compile Error in code: Unused Sub not Defined.

jbrouse

Active Member
Joined
Apr 28, 2005
Messages
329
Below is my Worksheet_BeforeRightClick() sub routine. It checks for the status of my ToggleButton, Edit, and if it is True, Right-Click runs sub Change_Shape. If it is False, Right-Clicking runs sub WorksheetDetail.

The problem is, Change_Shape is located in a module that is imported in when Edit.Value = True and exported out when Edit.Value = False. When I right-click with Edit.Value = True, it works fine. However, if I try to right-click with Edit.Value = False, I get a compile error, saying that Change_Shape is not defined. What I don't understand is, why is it even going into the Edit.Value = True portion of the If statement if Edit.Value = False? If I'm not calling that sub, why does it need to be defined?

Can anyone please assist me in modifying the code so that it will work properly? It would be greatly appreciated. Thanks!


Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    
    If Edit.Value = True Then
        Change_Shape
        Cancel = True
    ElseIf Edit.Value = False Then
        WorksheetDetail
        Cancel = True
    End If

End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about not importing or exporting/deleting code? In 30 years of software development, I have never come across a real system that required one to write code that modified code.

Edit: And, if you must edit code with code, create a dummy subroutine in another module that will always exist. This subroutine can call the here-today-gone-tomorrow subroutine.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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