View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
mike mike is offline
external usenet poster
 
Posts: 216
Default Loop with two workbooks

Hi.

My problem is how to properly run a loop in one workbook
that is referring to cells in another workbook. I know
how to run loops when I am in only one workbook, but once
I open another workbook, the macro references will point
to the active workbook.

In the sample code below, I want to run a loop from
LastCell to LastRow in Demos.XLS. Inside this loop, I
need an IF section of code that will search for a string
in another workbook. If the value is found, then the
values in Column 1,2,and 3 of that same row need to be
copied to columns 2,3, and 4 of row "i" in the first
workbook . Any help will be greatly appreciated!

Thanks,
Mike.

Dim LastRow As Long
Dim LastCell As Long
Dim IP As String
LastRow = Cells(Rows.Count, 10).End(xlUp).Row
LastCell = Cells(Rows.Count, 1).End(xlUp).Row - 1
Workbooks.Open Filename:="C:\Documents and
Settings\Mike\My Documents\IP Addresses.xls"
For i = LastCell To LastRow ' in Demos.xls
IP = Cells(i, 5)
'I need an IF section here that looks the IP value up
in
'Column 4 of The IP Addresses workbook. If the value
is found, then
'the values in Column 1,2,and 3 of that same row need
to be copied to
'columns 2,3, and 4 of row "i" in the first workbook
(Demos.xls).
Next i