Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to paste to the correct empty cell?

Status
Not open for further replies.

alwayslrN

IS-IT--Management
Jun 20, 2006
159
US
I came across thread707-1033618 which will, for the most part, help me with something I am currently working on in Excel 2002. However, I am not sure how to handle situations where the data being pasted needs to start in the next empty cell, but that next empty cell needs to start at the row that corresponds to the data that was copied from the original source. Confusing, I know, let me show an example.

(1) I have a source file that has several columns of data. Let's say 10 columns.

(2) From the source file I am copying specific columns of data. Let's say 4 columns that are not adjacent to one another AND in some instances, depending upon where we receive the file, those 4 columns can be in different cell locations. Note: I will be creating separate procedures to handle the file layout differences.

(3) I am then, for each of the 4 cells, individually pasting the data into specific cells in a different worksheet in a different workbook.

What I want to do is be able to add data to the next empty cell because the above will be repeated for each of the files that I have.

The thread mentioned above will work fine if I have something like the following in the pasted to worksheet.


Column1 Column2 Column3 Column4
100 20 500 8.5
200 30 150 7.5
400 40 700 7.5
500 50 800 8.5

BUT If I have the following:

Column1 Column2 Column3 Column4
100 20 8.5
200 30 7.5
400 40 7.5
500 50 8.5

and I paste additional records, how do I make sure to have the new records in column3 start at column3 row6 and not column3 row2? Note, for what I am doing column1 will always have data to paste.

Thanks
 
Use a variable to store the last row of data - there are 2 FAQs in this forum on how to get that.

Once done, you may use this in a range reference to paste the data e.g.

workbookX.somerange.copy

workbookY.Range("C" & LastRow + 1).paste

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Thanks Geoff - just to verify were you referring to faq707-2115 and faq707-2112?

Thanks

P
 
yup - them's the babies. Probably some other ways as well - most people have a preference and stick with it

Post back if you have any issues implementing the ideas

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top