+ Reply to Thread
Results 1 to 4 of 4

Select visible cells using vba

  1. #1
    Tony
    Guest

    Select visible cells using vba

    Hi there,

    Using vba code, I want to select a cell that has been filtered?

    ie.
    Range("A1").select
    Activecell.offset(2,0).select - this selects Range("A3") but is not
    visible.

    I want it to consider visible cells only.

    Any ideas?


  2. #2
    Tom Ogilvy
    Guest

    Re: Select visible cells using vba


    Range("A1").Select
    do
    ActiveCell.offset(1,0).Select
    Loop While ActiveCell.EntireRow.Hidden = True

    Did you want to select the second visible cell below the current selection
    rather than the next visible cell?

    --
    Regards,
    Tom Ogilvy


    "Tony" <[email protected]> wrote in message
    news:[email protected]...
    > Hi there,
    >
    > Using vba code, I want to select a cell that has been filtered?
    >
    > ie.
    > Range("A1").select
    > Activecell.offset(2,0).select - this selects Range("A3") but is not
    > visible.
    >
    > I want it to consider visible cells only.
    >
    > Any ideas?
    >




  3. #3
    Tony
    Guest

    Re: Select visible cells using vba

    Thanks Tom, this is great.
    To select a cell further down the filtered range (ie the 2nd visible cell),
    should I just repeat the do loop function, or is there a better way?

    In addition to selecting the 2nd visible cell, is there an easy way to copy
    just this entire row?

    Thanks again, this is a big help!
    Cheers,
    Tony



    "Tom Ogilvy" wrote:

    >
    > Range("A1").Select
    > do
    > ActiveCell.offset(1,0).Select
    > Loop While ActiveCell.EntireRow.Hidden = True
    >
    > Did you want to select the second visible cell below the current selection
    > rather than the next visible cell?
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Tony" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi there,
    > >
    > > Using vba code, I want to select a cell that has been filtered?
    > >
    > > ie.
    > > Range("A1").select
    > > Activecell.offset(2,0).select - this selects Range("A3") but is not
    > > visible.
    > >
    > > I want it to consider visible cells only.
    > >
    > > Any ideas?
    > >

    >
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    Re: Select visible cells using vba

    1) To continue down the filtered range, use the same method.

    If you want to loop throught the visible range and are using an autofilter
    in this example, copy filtered rows beginning with "ABC" to another sheet

    Dim cell as Range, rng as Range
    Dim rng1 as Ragne
    set rng = Activesheet.Autofilter.Range.Columns(1)
    set rng = rng.Offset(1,0).Resize(rng.rows.count -1,1)
    On Error Resume Next
    set rng1 = rng.specialCells(xlvisible)
    On Error goto 0
    if rng1 is nothing then
    msgbox "No visible rows"
    else
    for each cell in rng1
    if left(cell.Value,3) = "ABC" then
    cell.Entirerow.Copy Destination:= _
    Worksheets("Othersheet").Cells(rows.count,1).End(xlup)(2)
    end if
    Next
    End if

    --------------------
    2) To copy:

    ActiveCell.Entirerow.copy Destination:= _
    Worksheets("Othersheet").Cells(rows.count,1).End(xlup)(2)

    All code is untested and may contain typos.

    --
    Regards,
    Tom Ogilvy

    "Tony" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks Tom, this is great.
    > To select a cell further down the filtered range (ie the 2nd visible

    cell),
    > should I just repeat the do loop function, or is there a better way?
    >
    > In addition to selecting the 2nd visible cell, is there an easy way to

    copy
    > just this entire row?
    >
    > Thanks again, this is a big help!
    > Cheers,
    > Tony
    >
    >
    >
    > "Tom Ogilvy" wrote:
    >
    > >
    > > Range("A1").Select
    > > do
    > > ActiveCell.offset(1,0).Select
    > > Loop While ActiveCell.EntireRow.Hidden = True
    > >
    > > Did you want to select the second visible cell below the current

    selection
    > > rather than the next visible cell?
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Tony" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Hi there,
    > > >
    > > > Using vba code, I want to select a cell that has been filtered?
    > > >
    > > > ie.
    > > > Range("A1").select
    > > > Activecell.offset(2,0).select - this selects Range("A3") but is

    not
    > > > visible.
    > > >
    > > > I want it to consider visible cells only.
    > > >
    > > > Any ideas?
    > > >

    > >
    > >
    > >




+ 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