ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Activate/Select Problems (https://www.excelbanter.com/excel-programming/311968-activate-select-problems.html)

kls[_2_]

Activate/Select Problems
 
When I use the following code, everything works fine(I had a row
selected for copying in the first wrksheet. The row is copied to Row 54
of present sheet & Row2 of the 2nd sheet

Sub CopyTo()
Selection.Copy
Range("A54").PasteSpecial

Worksheets("Sent Messages").Range("A2:B2").PasteSpecial
End Sub
--------------

However, I need to install a sub that will detect if the row is already
populated and move down the column to the last row.

When I try:
Worksheets("Sent Messages").Range("A2:B2").Select
or
Worksheets("Sent Messages").Range("A2:B2").Activate

so I can proceed, I get an error message.

What am I doing wrong?
Thanks


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

DavidC[_2_]

Activate/Select Problems
 
You need to go to the very last row then ctrl page up to
find the last row of data. Then identify the row number
or cell address and that can then be used to tell the code
where to paste the data. rn in the code below will give
the row number for the last row of data. So rn+1 will be
the first empty row.

rn = Worksheets("sent messages").Range("A65536").End
(xlUp).Row

Also be carefull with selecting a row to copy and then
pasting it into a cell selection which differs from the
size of area copied. If copying a whole row, I usually
only paste into the cell in column A in the row required.

so if copying a row then paste command would be:

Worksheets(name of sheet).paste Destination:=Worksheets
(name of sheet).Range("A1")

where A1 is whichever row number you want to paste into.

Hope this helps

Regards
DavidC
-----Original Message-----
When I use the following code, everything works fine(I

had a row
selected for copying in the first wrksheet. The row is

copied to Row 54
of present sheet & Row2 of the 2nd sheet

Sub CopyTo()
Selection.Copy
Range("A54").PasteSpecial

Worksheets("Sent Messages").Range

("A2:B2").PasteSpecial
End Sub
--------------

However, I need to install a sub that will detect if the

row is already
populated and move down the column to the last row.

When I try:
Worksheets("Sent Messages").Range("A2:B2").Select
or
Worksheets("Sent Messages").Range("A2:B2").Activate

so I can proceed, I get an error message.

What am I doing wrong?
Thanks


*** Sent via Developersdex http://www.developersdex.com

***
Don't just participate in USENET...get rewarded for it!
.



All times are GMT +1. The time now is 06:39 PM.

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