Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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? . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
cursor movement | New Users to Excel | |||
Cursor Movement? | Excel Worksheet Functions | |||
Cursor movement in a macro | Excel Discussion (Misc queries) | |||
Cursor Movement in Macro | Excel Programming | |||
Cursor Movement in Macro | Excel Programming |