ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cursor Movement in Macro (https://www.excelbanter.com/excel-programming/273619-cursor-movement-macro.html)

Tim Zych[_2_]

Cursor Movement in Macro
 
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.


-----Original Message-----
Very simple question.

How do you move the cursor DOWN from a macro?

I am appending data from multipul database calls but
Excel does a

Selection.End(xlDown).Select
Range("A38").Select ***This line is the problem***

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.

What do I need to replace the second line of code with?

.



All times are GMT +1. The time now is 02:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com