You are here:

Excel/Unable to Click on my Macro Buttons

Advertisement


Question
QUESTION: Hi again Bill,

I've been trying to add some security to the macro code you’ve helped me with during the past week. Unfortunately I'm having a bit of trouble and I thought you might be able to tell me what I'm doing wrong and how to do it right.

As you may recall, the file that I'm working with has a worksheet containing data, formulas, and derived data. Essentially the formulas use the data to produce the derived data values.  I trigger each of the refresh macros by clicking one of two buttons - one to refresh detail view, one to refresh the summary view. I use the AutoFilter command in the first macro to toggle off the summary view created by the second macro.

At the end of this note, I'm including a copy of both macros.  As is, the macro code without the Protect commands works perfectly.  That's because I've commented out the various Protect commands.  As part of the macro code, the Protect commands were meant to prevent users from being able to change the actual data and from also seeing the formulas.  

In preparation to use these macros, I used the Format/Cells/Protection selection in Excel to explicitly lock and/or hide the appropriate columns.  Next I used the Tools/Protection/Protect Sheet selection to protect the worksheet. I activate these macros by clicking buttons I set up on the sheet.

The first few times I use the macros, they work as intended. But it seems that after any of them lock the sheet, I cannot click on any of the macros buttons I’ve set up on the sheet.   I have to go and manually UnProtect the worksheet in order to use the buttons again. But as soon as the sheet becomes protected again using the macros, I’m faced with exactly the same problem. None of the macro buttons on the worksheet would work.

Please let me know what I need to change to get things working properly.

Thank you.

Stan

---------------- Macros Follows -----------------

Sub CopyRight2Left()

Dim myCell As Range

Application.DisplayAlerts = False
Application.ScreenUpdating = False

Sheets("2-Year Data").Select

' ActiveSheet.Unprotect Password:=""
' ActiveSheet.Protect Password:="", UserInterFaceOnly:=True

' Save the current cell location
Set myCell = ActiveCell
Columns("B:AO").Select
Selection.AutoFilter

Sheets("2-Year Data").Range("GG3:GV14060").Copy
Sheets("2-Year Data").Range("I3").PasteSpecial Paste:=xlPasteValues
Sheets("2-Year Data").Range("I3").PasteSpecial Paste:=xlPasteFormats

Sheets("2-Year Data").Range("HA3:HM14060").Copy
Sheets("2-Year Data").Range("AC3").PasteSpecial Paste:=xlPasteValues
Sheets("2-Year Data").Range("AC3").PasteSpecial Paste:=xlPasteFormats

myCell.Select

' ActiveSheet.Protect Password:=""

Application.ScreenUpdating = True
Application.ScreenUpdating = True

End Sub

-------------------------------

Sub FilterCopyRight2Left()

   Dim myCell As Range

   Application.DisplayAlerts = False
   Application.ScreenUpdating = False

   Sheets("2-Year Data").Select

' Save the current cell location
   Set myCell = ActiveCell
'
'   ActiveSheet.Unprotect Password:=""
'  ActiveSheet.Protect Password:="", UserInterFaceOnly:=True

'    Selection.AutoFilter

 Sheets("2-Year Data").Range("GG3:GV14060").Copy
 Sheets("2-Year Data").Range("I3").PasteSpecial Paste:=xlPasteValues
 Sheets("2-Year Data").Range("I3").PasteSpecial Paste:=xlPasteFormats

 Sheets("2-Year Data").Range("HA3:HM14060").Copy
 Sheets("2-Year Data").Range("AC3").PasteSpecial Paste:=xlPasteValues
 Sheets("2-Year Data").Range("AC3").PasteSpecial Paste:=xlPasteFormats

   Columns("B:AO").Select
   Selection.AutoFilter
   Selection.AutoFilter Field:=2, Criteria1:="15:45"

   myCell.Select
'   ActiveSheet.Protect Password:=""
   Application.ScreenUpdating = True
   
End Sub


ANSWER: Try removing UserInterFaceOnly:=True

---------- FOLLOW-UP ----------

QUESTION: I followed your suggestion.  I continue to have the same problem.  There's a copy of the macro that I executed at the end of this message.

The problem seems to be caused by the AutoFilter command. If the Protect command is commented out, the AutoFilter command will execute, and it will either toggle on or off the drop-down box at the top of each column, and everything works perfectly.

But when the Protect Sheet command is inserted into the macro and executes, whenever the AutoFilter command executes and the drop-down boxes appear, the macro buttons no longer work.

Is there a parameter missing from the AutoFilter command?

--------------- Macro ----------------
Sub CopyRight2Left()

   Dim myCell As Range

   Application.DisplayAlerts = False
   Application.ScreenUpdating = False

   Sheets("2-Year Data").Select

   ActiveSheet.Unprotect Password:=""

' Save the current cell location
   Set myCell = ActiveCell
   Columns("B:AO").Select
   Selection.AutoFilter

 Sheets("2-Year Data").Range("GG3:GV14060").Copy
 Sheets("2-Year Data").Range("I3").PasteSpecial Paste:=xlPasteValues
 Sheets("2-Year Data").Range("I3").PasteSpecial Paste:=xlPasteFormats

 Sheets("2-Year Data").Range("HA3:HM14060").Copy
 Sheets("2-Year Data").Range("AC3").PasteSpecial Paste:=xlPasteValues
 Sheets("2-Year Data").Range("AC3").PasteSpecial Paste:=xlPasteFormats
 
   Range("I3:AO94").Select
   Selection.Locked = False
   Selection.FormulaHidden = False

   myCell.Select
   
  ActiveSheet.Protect Password:=""

  Application.ScreenUpdating = True
   Application.ScreenUpdating = True
   
End Sub


Answer
"...Is there a parameter missing from the AutoFilter command?...

No, there are none

Try NOT selecting the cells before doing the filter since you RARELY EVER have to select a cell or range before doing anything with that cell and/or range as I think I told you before when I suggested changes to your copying and pasting.

Ex from

Columns("B:AO").Select
Selection.AutoFilter

to:
Columns("B:AO").AutoFilter

See the common thread? - Select and Selection
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

All Answers

Answers by Expert:


Ask Experts

Volunteer


Bill

Expertise

I can provide help with most all EXCEL questions and most all questions about writing EXCEL macros. I have been developing macros for about 10 years in EXCEL and have switched to it from Lotus 1-2-3 after about 10 years of writing macros in it. Typically, I will not write a macro for you unless it is very short because of all the details a macro has to know about to work every time all the time. Please understand that I do not know it all and will be the first to say so. As politely as possible, I don't write macros for people on this site who need one, want one, seem to imply that they need one, and/or seem to think I am expected to write one UNLESS they are very short, quick, and simple. 99% of all macros are more involved than what you think and rarely am I provided with enough specific and complete details to have the code work the first time and every time. This typically means too many follow-up emails, and subsequent macro changes due to lack of specific details, just to get those details so that the macro would work, all of which is on my own free time. The voice of experience from responding to many questions from people who ask me to write a macro for them from this site tells me this. I don't mean to come across as unhelpful but macros are usually very specific and without ALL of the specifics the macro I would write will not address all of your needs and the layout, location, formatting, conditions, etc. of your data and any related files the macro would have to work with. What seems like a simple task to you is almost always more involved than what you think to have the macro ALWAYS work in EVERY situation. If you have a macro you have already written and have a question about it then perhaps I could help with that. I am sure and hope you can and do understand.

©2009 About.com, a part of The New York Times Company. All rights reserved.