Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jkg jkg is offline
external usenet poster
 
Posts: 3
Default Using an existing autofilter in protected sheet (with code)

Hi,

I've read a bunch of posts about a similar problem, but everything I read is
telling me that I should be able to do this - yet when I try, I get a run
time error every time.

I am using Excel 2003. In my spreadsheet, I have created an autofilter. It
is already in place. (I'm not creating a new one! I know you can't do that.)
Within this range being filtered, some cells are locked, some are not. I have
a button for "hide blank rows" and "show blank rows to enter new customer"
This button runs very simple code:

Selection.AutoFilter Field:=4, Criteria1:="<"

or without "Criteria1:="<" to show rows.

But when I protect the sheet - *even with choosing the allow AutoFilter
option* it still gives me the error:

Run-time error '1004':
You cannot use this command on a protected sheet. To unprotect the sheet,
use the Unprotect Sheet command (tools menu.......

I absolutely must be able to hide and show blank rows with the macro - I
don't trust the users to be able to navigate the autofilter on their own -
they're not Excel users, they're salespeople. But a big button that says
"hide" or "show" should be ok.

I even tried using code to "protect" the cells with a message box saying
"are you sure you want to change this formula?" and an option for "no" that
will undo the change, but the only way I can make that work is to tie it to
the Worksheet_Change event and trap only those changes where the Target is
within my protected range. But as soon as they click "no" to undo the change
- that changes the worksheet again and kicks off the "Are you sure you want
to change this?" again - which would confuse these people to no end.

HELP!

Thanks!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Using an existing autofilter in protected sheet (with code)

This should work in all versions of Excel after xl97.

Private Sub CommandButton1_Click()
Dim rng As Range
ActiveSheet.EnableAutoFilter = True
ActiveSheet.Protect Password:="ABC", UserInterfaceOnly:=True
Set rng = ActiveSheet.AutoFilter.Range
rng.AutoFilter Field:=4, Criteria1:="<"
End Sub

Private Sub CommandButton2_Click()
Dim rng As Range
ActiveSheet.EnableAutoFilter = True
ActiveSheet.Protect Password:="ABC", UserInterfaceOnly:=True
Set rng = ActiveSheet.AutoFilter.Range
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
End Sub

It worked fine for me (xl2003). My sheet was protected with a password of ABC

--
Regards,
Tom Ogilvy



"JKG" wrote:

Hi,

I've read a bunch of posts about a similar problem, but everything I read is
telling me that I should be able to do this - yet when I try, I get a run
time error every time.

I am using Excel 2003. In my spreadsheet, I have created an autofilter. It
is already in place. (I'm not creating a new one! I know you can't do that.)
Within this range being filtered, some cells are locked, some are not. I have
a button for "hide blank rows" and "show blank rows to enter new customer"
This button runs very simple code:

Selection.AutoFilter Field:=4, Criteria1:="<"

or without "Criteria1:="<" to show rows.

But when I protect the sheet - *even with choosing the allow AutoFilter
option* it still gives me the error:

Run-time error '1004':
You cannot use this command on a protected sheet. To unprotect the sheet,
use the Unprotect Sheet command (tools menu.......

I absolutely must be able to hide and show blank rows with the macro - I
don't trust the users to be able to navigate the autofilter on their own -
they're not Excel users, they're salespeople. But a big button that says
"hide" or "show" should be ok.

I even tried using code to "protect" the cells with a message box saying
"are you sure you want to change this formula?" and an option for "no" that
will undo the change, but the only way I can make that work is to tie it to
the Worksheet_Change event and trap only those changes where the Target is
within my protected range. But as soon as they click "no" to undo the change
- that changes the worksheet again and kicks off the "Are you sure you want
to change this?" again - which would confuse these people to no end.

HELP!

Thanks!!

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 in protected sheet Javier Excel Worksheet Functions 5 March 24th 08 05:56 PM
Protected Sheet and AutoFilter Steven Excel Programming 2 September 15th 06 02:13 AM
Protected sheet and Autofilter? harpscardiff[_19_] Excel Programming 4 January 25th 06 05:58 PM
Autofilter protected sheet vecia[_4_] Excel Programming 4 September 10th 05 08:25 AM
AutoFilter on a Protected sheet Olle[_2_] Excel Programming 1 June 15th 04 08:12 AM


All times are GMT +1. The time now is 02:03 AM.

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"