Cursor Movement in Macro

T

Tim Zych

As each time I run the macro I want to go to the end then
down one line to add the next block of data.

Another way: set a range object to that cell and then
refer to that to update your sheet.

Dim cell as Range
Set cell = Cells(Rows.Count,"A").End(xlup).offset(1)
'Gives you the next available cell to paste your data
'Now you can paste it there
'Assuming you have already copied the contents to the
clipboard:
cell.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

If you really want to activate the cell, then:
Cells(Rows.Count,"A").End(xlUp).Offset(1).Select

Also keep in mind the difference between xlDown and xlUp.
xlDown directs downward and stops at the first or last non-
empty cell of a contiguous area, depending on where the
starting range is. xlUp does the same (except that it
directs upward), and since the macro above starts at row
65536 and looks up from there, it always returns the
bottom-most empty cell in column A.

If you are pasting data and some of the data have blanks,
you have to use xlUp. Using xlDown for this activity may
overwrite some of your pasted data (I say 'may' because
non-Excel data exports sometimes contain empty cell gunk
that Excel thinks is data, therfore not falling victim to
the usual xlDown behavior with respect to empty cells).
Use xlDown only if you never anticipate to have blanks in
the pasted data. As a general rule, I use xlUp.
 

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