Macro won't run when button is clicked

crussom1

New Member
Joined
Jan 28, 2014
Messages
4
So I have a macro that works fine when I go to Developer tab > Macros > (select the macro) > Run. But then I assigned the macro to a button (I tried a rectangle shape first, then a form control button - both were the same), it gives me an error when I click the button. The error says "Cannot run the macro "p-5100.xlsm'!GoalFormat2'. The macro may not be available in this workbook or all macros may be disabled". The macro is definitly in the workbook because I can run it from the Developer tab and macros are enabled (there is another macro which runs automatically upon a selection change event which works fine...) The macro is supposed to let people select some cells within a specific range, then press a button to turn them green (I know this is kind of silly because this is like a one-click thing anyway but it is part of a larger project). The really odd thing is it works fine when I run it myself through the developer tab but not when I click the button. The button worked before when I was using 2007 (In fact files I already created with the button in them still work), but new files created from this template in 2013 have the problem.
Code:
Sub GoalFormat2()
If Not Intersect(Range("I25:O29"), Selection) Is Nothing Then
    'Change all the cells from column I to O in that row to white
    Range("I" & ActiveCell.Row & ":O" & ActiveCell.Row).Interior.Color = 16777215
    'Change the selected cells to green
    Selection.Interior.ThemeColor = xlThemeColorAccent3
End If
End Sub
 
@ckhang, as with virtually all the other posts in the thread you are unlikely to get a resolution unless you post the code you are using, where you have placed the code and describe your exact issue.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,216,086
Messages
6,128,736
Members
449,466
Latest member
Peter Juhnke

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