user1857833
user1857833

Reputation: 13

Excel Macro Copy paste into another xls file in the first empty row

I'm currently working on a digital project and I have to analyze data from more than 100 FB excel files.

Part of my analysis process consist in extracting data from specific cells that are always the same.

As you understood I would like to make a macro in order to avoid useless waste of time.

I know how to extract it in the file, but I would like to adapt my macro in order to copy it in another file.

The code I have is the following:

***Range("A9:D9").Select

Selection.Copy

Windows("test2.xlsx").Activate

ActiveSheet.Paste***

Now I would like to paste the data in an empty row in order to have hundreds of rows one bellow the other (one for each FB extract).

Would someone give me the correct code in order to avoid a huge waste of time?

Upvotes: 1

Views: 12737

Answers (2)

Desert Spider
Desert Spider

Reputation: 778

Here is a snippit of code I use for similar operations to select the next available cell.

'Insert after Your Windows("test2.xlsx").Activate in place of your paste Code.....
'This gives you the variable for the last cell with a value
lastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
'This section selects the next cell below your last used cell and pastes the information.
ActiveSheet.Range("A" & lastRow + 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Rest of Code....

I hope this is what you were looking for.

Upvotes: 0

Tim Williams
Tim Williams

Reputation: 166126

If the macro is in the "summary" workbook and the FB file is open and active:

ActiveSheet.Range("A9:D9")Copy _
   ThisWorkbook.Sheets("Data").Cells(Rows.Count,1).End(xlup).offset(1,0)

Upvotes: 0

Related Questions