View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
maboli maboli is offline
external usenet poster
 
Posts: 2
Default AutoFilter method of Range class failed

The first version of creating an autofilter in Excel works fine, but why do I
get an
exception on the second version?

I am coding in VB.NET (VB 2005).
(I would like to compile my code with option strict set to ON and then only
the second version does compile)

...
excelWorksheet.Activate()

' VERSION 1: the following 3 lines work fine
Dim range1 As Excel.Range = excelWorksheet.Range("A:A")
range1.Select()
excelWorksheet.Application.Selection.AutoFilter()


' VERSION 2: throws an Exceptions
Dim range2 As Excel.Range = CType(excelWorksheet.Range("B:B"),
Excel.Range)
range2.Select()
Dim rangeSel As Excel.Range =
CType(excelWorksheet.Application.Selection, Excel.Range)
rangeSel.AutoFilter() ' Exception: "AutoFilter method of Range
class failed"

Help would be appreciated!