LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.dotnet.languages.vb,microsoft.public.vb.ole.automation,microsoft.public.vb.ole
external usenet poster
 
Posts: 2
Default Can't create AutoFiltered Excel worksheet using VB.NET


John Brock wrote:
In article ,
Ron de Bruin wrote:
Hi

See this page
http://www.contextures.com/xlautofilter03.html


The VBA (not VB.NET) example on that page is:

Sub TurnAutoFilterOn()
'check for filter, turn on if none exists
If Not ActiveSheet.AutoFilterMode Then
ActiveSheet.Range("A1").AutoFilter
End If
End Sub

I don't see how this is different than what I am doing now. My
'ws' variable *is* the active worksheet (in fact the only worksheet).
I tried using a single cell range, as in the example, but that
makes no difference. The AutoFilter statement still throws an
exception.

The example given for turning off AutoFiltering uses an AutoFilterMode
variable. I changed my code to:

ws.AutoFilterMode = true
rng = ws.Range("MyTableRange")
rng.AutoFilter()

But now the first statement throws an exception, with the even less
enlightening message:

Exception from HRESULT: 0x800A03EC.


Lifted from the MSDN page on AutoFilterMode at
http://msdn2.microsoft.com/en-us/mic...erm ode.aspx:

Remarks

You can set this property to false to remove the arrows, but you
cannot set it to true.

That would explain why the line 'ws.AutoFilterMode = true' throws an
exception.
I'm not very familiar with Excel programming, but in every example I
could find, everyone always sets AutoFilterMode to false (which is
allowed) before calling AutoFilter on their range object. So I would
say try this:

ws.AutoFilterMode = false
rng = ws.Range("MyTableRange")
rng.AutoFilter()

Setting AutoFilterMode to false also has the side-effect of removing
any previous AutoFilters that were on the worksheet, which I guess is
important before you call AutoFilter() again...

<snip

Mike S



 
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
how do I create GST worksheet in excel jl New Users to Excel 7 July 2nd 09 07:20 PM
How do I create a worksheet within a worksheet in Excel? Julieee Excel Worksheet Functions 1 December 23rd 05 01:33 AM
create linked autofiltered sheets? wembley Links and Linking in Excel 0 March 26th 05 04:37 AM
Create new excel worksheet Lillian Excel Programming 2 December 4th 04 05:29 AM
Create Excel Worksheet in C# / VB Horst Walter Excel Programming 8 January 5th 04 03:34 PM


All times are GMT +1. The time now is 06:51 PM.

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"