Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Autofilter and protection

Again I have hit a minor problem.
Have a macro that autofilters a range on a worksheet to 0
I have an active x control at the bottom of the workbook
that calls the Macro.
The problem is that I need to protect the workbook. I
have unlocked all of the cells and controls that I am
going to allow the user to change. I have even unlocked
the entire column that the macro uses to filter the
sheet. (I will hide this column before protecting the
sheet)
Unprotected the macro works fine. After protecting the
macro I get a runtime error 1004.




Worksheets("Front").Activate
Cells.Select
Selection.PageBreak = xlNone
Range("F28:F332").Select
Range("F28").Activate

Selection.AutoFilter Field:=1, Criteria1:="0",
Operator:=xlAnd
ActiveWindow.SelectedSheets.PrintPreview

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Autofilter and protection

Since this code is associated with a control from the control toolbox toolbar,
it's probably behind the worksheet that owns the control.

And I'm betting that that worksheet is different than "Front".

If both those things are true, then this might work:
With Worksheets("Front")
.Select
.ResetAllPageBreaks
.Range("F28:f332").AutoFilter Field:=1, Criteria1:="0"
End With
ActiveWindow.SelectedSheets.PrintPreview

(and if you're using xl97, make sure you change the .takefocusonclick property
to false (or add activecell.activate to the top of your code). (It's a bug
fixed with xl2k.)

When you refer to Cells or range("F28:f332") in a general module, this
unqualified reference will go back to the activesheet.

But if the code is behind a worksheet, then those ranges belong not to the
activesheet, but to the sheet that owns the code.

Jerett wrote:

Again I have hit a minor problem.
Have a macro that autofilters a range on a worksheet to 0
I have an active x control at the bottom of the workbook
that calls the Macro.
The problem is that I need to protect the workbook. I
have unlocked all of the cells and controls that I am
going to allow the user to change. I have even unlocked
the entire column that the macro uses to filter the
sheet. (I will hide this column before protecting the
sheet)
Unprotected the macro works fine. After protecting the
macro I get a runtime error 1004.

Worksheets("Front").Activate
Cells.Select
Selection.PageBreak = xlNone
Range("F28:F332").Select
Range("F28").Activate

Selection.AutoFilter Field:=1, Criteria1:="0",
Operator:=xlAnd
ActiveWindow.SelectedSheets.PrintPreview


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofilter and protection tankerman Excel Discussion (Misc queries) 2 December 14th 06 06:06 AM
How to Sort within AutoFilter with Protection on (and AutoFilter . giblon Excel Discussion (Misc queries) 1 February 16th 06 12:23 PM
access to autofilter with protection derwood Excel Discussion (Misc queries) 0 November 13th 05 02:02 PM
Using Autofilter with Protection on Duncan Help Excel Worksheet Functions 1 November 8th 05 05:13 PM
Autofilter and protection RJH Excel Programming 5 December 18th 03 05:52 AM


All times are GMT +1. The time now is 02:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"