Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Prevent ShowAllData Method from failing

Hi,
I have an Excel 2007 worksheet that has autofilters and macros assigned to
option buttons in a Group Box that carry out some of the filtering. One
button is the ShowAllData button that removes the filter. If the ShowAllData
button is selected and then selected again (before any other button in the
group is selected) I get a Run Time Error that the ShowAllData method of
worksheet class failed. How do I prevent this error? I'm very new to VB.
The code below is what I'm having trouble with.
Thanks,
Jim

Sub UnhideBlanks()
'
' UnhideBlanks Macro
'
ActiveSheet.Unprotect Password:="sivle"
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
ElseIf ActiveSheet.AutoFilterMode = False Then
Else
ActiveSheet.Protect Password:="sivle", DrawingObjects:=True,
Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Prevent ShowAllData Method from failing

With ActiveSheet
.unprotect ...
If .FilterMode Then
.ShowAllData
End If
.protect...
end with



JimAA wrote:

Hi,
I have an Excel 2007 worksheet that has autofilters and macros assigned to
option buttons in a Group Box that carry out some of the filtering. One
button is the ShowAllData button that removes the filter. If the ShowAllData
button is selected and then selected again (before any other button in the
group is selected) I get a Run Time Error that the ShowAllData method of
worksheet class failed. How do I prevent this error? I'm very new to VB.
The code below is what I'm having trouble with.
Thanks,
Jim

Sub UnhideBlanks()
'
' UnhideBlanks Macro
'
ActiveSheet.Unprotect Password:="sivle"
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
ElseIf ActiveSheet.AutoFilterMode = False Then
Else
ActiveSheet.Protect Password:="sivle", DrawingObjects:=True,
Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
End If

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Prevent ShowAllData Method from failing

Hi Jim,

AutoFilterMode tests if AutoFilter is applied to the worksheet (Like
AutoFilter drop downs are present)

FilterMode test if a filter has actually been set

Sub UnhideBlanks()
'
' UnhideBlanks Macro
'
ActiveSheet.Unprotect Password:="sivle"
If ActiveSheet.AutoFilterMode = True Then
If ActiveSheet.FilterMode = True Then
ActiveSheet.ShowAllData
End If
ElseIf ActiveSheet.AutoFilterMode = False Then
Else
'ActiveSheet.Protect Password:="sivle", DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
End If

End Sub

--
Regards,

OssieMac


"JimAA" wrote:

Hi,
I have an Excel 2007 worksheet that has autofilters and macros assigned to
option buttons in a Group Box that carry out some of the filtering. One
button is the ShowAllData button that removes the filter. If the ShowAllData
button is selected and then selected again (before any other button in the
group is selected) I get a Run Time Error that the ShowAllData method of
worksheet class failed. How do I prevent this error? I'm very new to VB.
The code below is what I'm having trouble with.
Thanks,
Jim

Sub UnhideBlanks()
'
' UnhideBlanks Macro
'
ActiveSheet.Unprotect Password:="sivle"
If ActiveSheet.AutoFilterMode = True Then
ActiveSheet.ShowAllData
ElseIf ActiveSheet.AutoFilterMode = False Then
Else
ActiveSheet.Protect Password:="sivle", DrawingObjects:=True,
Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
End If

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Prevent ShowAllData Method from failing

Hi again Jim,

The following method of testing both AutoFilterMode and FilterMode together
in the one If statment also works.

Note there is no need to use = True because it is understood. (If testing
for False then you use = False)

Also I think your use of ElseIf and Else is not correct. I think the Else
part will never be processed under any conditions.

Note the space and underscore at the end of a line is a line break in an
otherwise single line of code. (I used them extensively when posting here
because it prevents unwanted line breaks in the post and the code can be
copied directly into your project.

Sub UnhideBlanks()
'
' UnhideBlanks Macro
'
ActiveSheet.Unprotect Password:="sivle"
If ActiveSheet.AutoFilterMode _
And ActiveSheet.FilterMode Then

ActiveSheet.ShowAllData

ElseIf ActiveSheet.AutoFilterMode = False Then
ActiveSheet.Protect Password:="sivle", _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
AllowSorting:=True, _
AllowFiltering:=True
End If

End Sub

--
Regards,

OssieMac


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Prevent ShowAllData Method from failing

Thanks Dave and OssieMac, I tried both solutions and they did exactly what I
wanted.

"OssieMac" wrote:

Hi again Jim,

The following method of testing both AutoFilterMode and FilterMode together
in the one If statment also works.

Note there is no need to use = True because it is understood. (If testing
for False then you use = False)

Also I think your use of ElseIf and Else is not correct. I think the Else
part will never be processed under any conditions.

Note the space and underscore at the end of a line is a line break in an
otherwise single line of code. (I used them extensively when posting here
because it prevents unwanted line breaks in the post and the code can be
copied directly into your project.

Sub UnhideBlanks()
'
' UnhideBlanks Macro
'
ActiveSheet.Unprotect Password:="sivle"
If ActiveSheet.AutoFilterMode _
And ActiveSheet.FilterMode Then

ActiveSheet.ShowAllData

ElseIf ActiveSheet.AutoFilterMode = False Then
ActiveSheet.Protect Password:="sivle", _
DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
AllowSorting:=True, _
AllowFiltering:=True
End If

End Sub

--
Regards,

OssieMac




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
Select method failing CDM Excel Programming 1 December 31st 09 06:52 AM
copy method of object failing vj2india Excel Programming 0 April 20th 06 02:21 AM
Select Method Failing cmk18[_8_] Excel Programming 2 July 11th 05 11:53 PM
Publish method failing, can't understand why Mark Excel Programming 0 June 22nd 05 07:52 PM
add method of validation failing mark kubicki Excel Programming 2 April 19th 05 08:08 PM


All times are GMT +1. The time now is 05:01 AM.

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

About Us

"It's about Microsoft Excel"