+ Reply to Thread
Results 1 to 3 of 3

Excel03 - empty cells and SpecialCells ( xlVisible )

  1. #1
    Chris Paterson
    Guest

    Excel03 - empty cells and SpecialCells ( xlVisible )

    Hi,

    I have a sheet of data that has the Autofilter applied and I want to get a
    column of filtered data and transfer it to another sheet. The code below
    works most of the time but when I try to grab a range of data and the
    filtered sheet does not show any data (because I have filtered using a
    criteria that does not match any data in the column under consideration - I
    can't change this unfortunately) I get an Error 1004 "Cells were not found"
    and the routine crashes out.

    > ' Code applies autofiltering based on user entered criteria before this
    > section
    >
    > ' Copy Task Numbers
    > Set rng1 = Worksheets("FEPivot").Range("K6:K500")
    > Set rng1 = rng1.SpecialCells(xlVisible)
    > rng1.Copy Destination:=Worksheets("StatusSummary").Range("A29")
    >
    > ' Code continues...


    What I want to do is if the range selected does not contain any cells with
    data in just have the code step over these lines onto the next set of
    scripts. Is the an approach that will allow me to do this?

    Regards

    Chris



  2. #2
    Tom Ogilvy
    Guest

    Re: Excel03 - empty cells and SpecialCells ( xlVisible )

    Dim rng1 as Range, rng2 as Range
    ' Copy Task Numbers
    Set rng1 = Worksheets("FEPivot").Range("K6:K500")
    Set rng2 = nothing
    On Error Resume Next
    Set rng2 = rng1.SpecialCells(xlVisible)
    On Error goto 0
    if not rng2 is nothing then
    rng2.Copy Destination:=Worksheets("StatusSummary").Range("A29")
    end if
    --
    Regards,
    Tom Ogilvy


    "Chris Paterson" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I have a sheet of data that has the Autofilter applied and I want to get a
    > column of filtered data and transfer it to another sheet. The code below
    > works most of the time but when I try to grab a range of data and the
    > filtered sheet does not show any data (because I have filtered using a
    > criteria that does not match any data in the column under consideration -

    I
    > can't change this unfortunately) I get an Error 1004 "Cells were not

    found"
    > and the routine crashes out.
    >
    > > ' Code applies autofiltering based on user entered criteria before

    this
    > > section
    > >
    > > ' Copy Task Numbers
    > > Set rng1 = Worksheets("FEPivot").Range("K6:K500")
    > > Set rng1 = rng1.SpecialCells(xlVisible)
    > > rng1.Copy Destination:=Worksheets("StatusSummary").Range("A29")
    > >
    > > ' Code continues...

    >
    > What I want to do is if the range selected does not contain any cells with
    > data in just have the code step over these lines onto the next set of
    > scripts. Is the an approach that will allow me to do this?
    >
    > Regards
    >
    > Chris
    >
    >




  3. #3
    Chris Paterson
    Guest

    Re: Excel03 - empty cells and SpecialCells ( xlVisible )

    Many thanks Tom, crisis over...

    "Tom Ogilvy" <[email protected]> wrote in message
    news:uIrY0Y%[email protected]...
    > Dim rng1 as Range, rng2 as Range
    > ' Copy Task Numbers
    > Set rng1 = Worksheets("FEPivot").Range("K6:K500")
    > Set rng2 = nothing
    > On Error Resume Next
    > Set rng2 = rng1.SpecialCells(xlVisible)
    > On Error goto 0
    > if not rng2 is nothing then
    > rng2.Copy Destination:=Worksheets("StatusSummary").Range("A29")
    > end if
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Chris Paterson" <[email protected]> wrote in message
    > news:[email protected]...
    >> Hi,
    >>
    >> I have a sheet of data that has the Autofilter applied and I want to get
    >> a
    >> column of filtered data and transfer it to another sheet. The code below
    >> works most of the time but when I try to grab a range of data and the
    >> filtered sheet does not show any data (because I have filtered using a
    >> criteria that does not match any data in the column under consideration -

    > I
    >> can't change this unfortunately) I get an Error 1004 "Cells were not

    > found"
    >> and the routine crashes out.
    >>
    >> > ' Code applies autofiltering based on user entered criteria before

    > this
    >> > section
    >> >
    >> > ' Copy Task Numbers
    >> > Set rng1 = Worksheets("FEPivot").Range("K6:K500")
    >> > Set rng1 = rng1.SpecialCells(xlVisible)
    >> > rng1.Copy Destination:=Worksheets("StatusSummary").Range("A29")
    >> >
    >> > ' Code continues...

    >>
    >> What I want to do is if the range selected does not contain any cells
    >> with
    >> data in just have the code step over these lines onto the next set of
    >> scripts. Is the an approach that will allow me to do this?
    >>
    >> Regards
    >>
    >> Chris
    >>
    >>

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1