VBA Select the previous visible cell in a filtered table.

morest38

New Member
Joined
Nov 3, 2016
Messages
4
Hi Guys,
I'm trying the select using vba the previous visible cell in a filtered sheet.

Code:
Dim rng As RangeSet rng = Range(Cells(ActiveCell.Row + 1, 1), Cells(Rows.Count, 1))
rng.SpecialCells(xlCellTypeVisible).Cells(1).Select
ActiveCell.Offset(0, 17).Activate

Here is a code I have that does exactly that but for the next cell below. I want to make it so that it select the previous one instead.
Anyone can help? Thank you so much for any help!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
One way

Code:
Sub SelPrevCell()
    Dim R As Range, rng As Range, rngV As Range
    Dim I As Long

    Set rng = Range(Cells(1, 1), Cells(Rows.count, 1))    'column A
    Set rngV = rng.SpecialCells(xlCellTypeVisible)

    If ActiveCell.Row > 1 And ActiveCell.Column = 1 Then
        For I = -1 To -ActiveCell.Row Step -1
            Set R = ActiveCell.Offset(I, 0)
            If Not Application.Intersect(R, rngV) Is Nothing Then
                Exit For
            End If
        Next I
    End If

    If Not R Is Nothing Then
        R.Select                                      'select previous visible cell
    End If
End Sub
 
Upvote 0
Another option:
Code:
Dim c As Range
Set c = ActiveCell
    Do
        If c.Row = 1 Then Exit Do
        Set c = c.Offset(-1)
    Loop Until c.Rows.Height <> 0
c.Activate
 
Upvote 0

Forum statistics

Threads
1,216,855
Messages
6,133,098
Members
449,778
Latest member
dep1969

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top