• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Assigning a Button

KishorKK

Member
Hi All,

When i am trying to assign a button in excel taking from shape, i am getting this error?
How to overcome this? Pls explain
upload_2016-11-21_23-21-4.png
 
I suspect you are referencing macro in worksheet module. Instead, put your sub/macro in regular module.

If that doesn't fix the issue, upload sample workbook.
 
Regular module = When you add module in VBE (editor).
Most macro that's referenced by button/shapes should reside here.

upload_2016-11-21_13-18-1.png

Sheet1 = Worksheet Module
When you want to run the code tied to specific cell change, selection change on a given sheet. Code goes here.

ThisWorkbook = Workbook Module
When you want to run the code when workbook is opened, closed... or when you want to run the code on all worksheets when some change is made etc. Code goes here.
 
in sheet5 i want to assign macro can you explain with this
 

Attachments

  • VBA_Practise.xlsm
    30.8 KB · Views: 3
yeah i know!! only one with that i have to generate result, take any sub with the click i have to get result
 
Hi ,

The problem is that If1 can also refer to a worksheet cell !

Name your macros with longer names , so that they cannot be taken to refer to a worksheet cell ; for example , instead of If1 , if you rename the same macro to LongerIf1 , then the qualifying Function_IF is not required.

You can directly assign the macro LongerIf1.

Narayan
 
What Narayan said.

It's always bad idea to name subs or variables with string/value that can conflict with system.

Typical way to avoid such issue:
1. For variables precede it with "my"
2. For subs "Name_Numeric" should work. Ex: if_1
 
Back
Top