scroll through visible rows only

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I'm using this code to scroll through each row, however if the rows are filtered I would like to scroll through only the visible rows. Can someone assist with a vba code to only scroll through the visible rows. Thanks

VBA Code:
Private Sub spNav_SpinDown()
Dim LRow As Long

LRow = Application.Max(7, Range("A" & Rows.Count).End(xlUp).Row)

If Range("A7") > vbNullString Then Cells(Application.Min(LRow, selection.Row + 1), "A").Select
end sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
May be:
VBA Code:
Private Sub spNav_SpinDown()
Dim LRow As Long, cell As Range
LRow = Application.Max(7, Range("A" & Rows.Count).End(xlUp).Row)
If Range("A7") > vbNullString Then
    For Each cell In Range("A1:A" & LRow).SpecialCells(xlCellTypeVisible)
        If cell.Row > Selection.Row Then
            cell.Select
            Exit Sub
        End If
    Next
End If
End Sub
 
Upvote 0
Thank you for the help. Greatly appreciate it. Couple of question....

1. This works if I scroll down, but it does not work if I scroll up. What do I need to adjust?
2. Is there no way to adjust the 1-line code I used instead of looping through each row?
 
Upvote 0
After doing some research, I discovered this code. Only problem, it selects the entire row. How can I adjust the code to only move the cursor up 1 row without selecting the entire row?

VBA Code:
    Dim i As Long

    For i = ActiveCell.Row - 1 To 2 Step -1
        If Rows(i).Hidden = False Then
            Rows(i).Select
            Exit For
        End If
    Next i
 
Upvote 0
What columns do you want selected?
 
Upvote 0
I don't want the entire column or row selected. I just want the cursor to move up or down on the visible rows only.
 
Upvote 0
Maybe...

VBA Code:
Sub Option1()
    Dim i As Long

    For i = ActiveCell.Row - 1 To 2 Step -1
        If Rows(i).Hidden = False Then
            Cells(i, ActiveCell.Column).Select
            Exit For
        End If
    Next i
End Sub
 
Upvote 1
Solution
The code works great Mark. How do I stop it from passing the first filtered row?

Thank you very much. Greatly appreciate your help :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,307
Messages
6,124,163
Members
449,146
Latest member
el_gazar

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