Help with Excel VBA (Copy between 2 workbooks)

Keand31

New Member
Joined
Jul 25, 2011
Messages
4
Hi all.

Long time reader, first time poster.
First up, I'm a complete noob regarding VBA.

I've got, I hope, a small problem I hope you guys can help with.
I have 2 workbooks where I need to copy from one to the other.
First workbook is named Data.xls and second is named Statistik 2011.xls.

Data.xls contains 10 rows with data.
I am trying to copy data from worksheet1 -row 9 ("I") to Statistik 2011.xls if it fulfills a certain match.
I have, in the Data.xls, made a formula that takes todays date minus 7 days.
Now if the date in row 10 ("J" - Data.xls) is bigger or equal than todays date minus 7 then it should copy all the cells in row 9 ("I") to Statistik 2011.xls worksheet3 "Indtastningsark" - row 9 ("I") BUT it should check and find the last used cell in that row + 1 and insert the data it copied from Data.xls

I can't seem to find the "Add file button" but if anyone wants a copy of the 2 files please let me know.
I have look and read all around the net withuot finding exactly what I need, so I've tried to put different things together and giving it a twist of my own.

The code I've used is this:

Code:
Sub Copy()
    
    Workbooks.Open Filename:="Statistik 2011.xls", UpdateLinks:=0
    ThisWorkbook.Activate
    x = 2
    Do While Cells(x, 9) <> ""
    If Cells(x, 9) >= Range("K1") Then
    Worksheets("Ark1").Rows(x).Copy
    Workbooks("Statistik 2011.xls").Activate
    Worksheets("Indtastningsark").Activate
    erow = Cells(Rows.Count, "I").End(xlUp).Offset(1, 0).Row
    ActiveSheet.PasteSpecial Destination:=Worksheets("Indtastningsark").Rows(erow)
    End If
    ThisWorkbook.Activate
    Worksheets("Ark1").Activate
    x = x + 1
    Loop
End Sub

Cheers and thanks in advance.

/Kenneth
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Sorry just forgot one thing.
Workbook Data.xls is already open and is where I run the Macro. :)

/Kenneth.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top