Loop

F

Frank

Hi All,

I have got a question i can't find here:

I have to files: File1.xls and File2.xls

In file1.xls there is a Cell (C6) that has a value I want to copy to
File2.xls in Column A as long there is a value in Column B of File2.xls
I need to do a loop but i can't get the correct code for it.

Can someone help me with this?

Thanks!

BR
 
G

Gary''s Student

Sub demo()
Workbooks("File2.xls").Activate
Sheets("Sheet1").Activate
For i = 1 To Rows.Count
If IsEmpty(Cells(i, "B")) Then
Exit For
End If
Next
i = i - 1

Set r2 = Range("A1:A" & i)
Set r1 = Workbooks("File1.xls").Sheets("Sheet1").Range("C6")

r1.Copy r2
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top