Loop

G

Guest

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

Guest

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

Similar Threads

Loop 1
Macro Help 3
Connect Files 4
Macro attached to Menu Command Button 2
Array Formula in VBA 6
Help - I'm getting desperate 7
Exporting & Importing with macros 2
I need a VB script for Excel 5

Top