How can I move the cell pointer down one row in a macro command?

K

Ken

I am trying to find the macro command that automatically move the cell
pointer down one row. Exampl: for the end-up command you would write:
Selection.End(xlUp).Select .... What would it be to just move down One
cell????
 
G

GM

What about a sheet that has filtered rows?
With the keyboard I just hit "Down".

this code works if all the rows are displayed.
activecell.offset(1,0).select

What can I do to move across rows in a filtered sheet?
I need to move only across the displayed rows.

Thanks.
GM.



Dave Peterson said:
Or just
activecell.offset(1,0).select
 
D

Dave Peterson

One way is to just check after you move.

do
activecell.offset(1,0).select
if activecell.entirerow.hidden = false then
exit do
end if
loop

=====
It's not usually necessary to select a cell to work with it. If I wanted to
loop through each of the cells/rows in a filtered range, I could do something
like:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRngV As Range

With Worksheets("sheet1")
Set myRngV = Nothing
On Error Resume Next
With .AutoFilter.Range.Columns(1)
Set myRngV = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With
On Error GoTo 0

If myRngV Is Nothing Then
MsgBox "no visible cells in autofilter range"
End If
End With

For Each myCell In myRngV.Cells
'do anything I want to the cell/row.
MsgBox myCell.Address(0, 0)
Next myCell

End Sub
What about a sheet that has filtered rows?
With the keyboard I just hit "Down".

this code works if all the rows are displayed.
activecell.offset(1,0).select

What can I do to move across rows in a filtered sheet?
I need to move only across the displayed rows.

Thanks.
GM.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top