Thread: Macro Formula
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Joe via OfficeKB.com Joe via OfficeKB.com is offline
external usenet poster
 
Posts: 9
Default Macro Formula

Will this look through all my wrkbks? the file names are wrkbk1, wrkbk2,
wrkbk3, etc. all the way to wrkbk10.

Joel wrote:
try this code.

Sub lookupbooks()


'this should be workbook a
Set wsh1 = ThisWorkbook.Worksheets(1)

wsh1.Activate
lastrow = wsh1.Cells(Rows.Count, 1).End(xlUp).Row
Set InvoiceRange = wsh1.Range(Cells(1, 1), Cells(lastrow, 1))

For Each cell1 In InvoiceRange

InvoiceNumber = cell1.Value
For Each wbk1 In Application.Workbooks

If StrComp(wbk1.Name, ThisWorkbook.Name) < 0 Then
With wbk1.Worksheets(1)
.Activate
lastrow = .Cells(Rows.Count, 10).End(xlUp).Row
Set InvoiceRange2 = .Range(Cells(1, 10), Cells(lastrow, 10))

For Each cell2 In InvoiceRange2

If (InvoiceNumber = cell2.Value) Then

.Range(Cells(cell2.Row, 1), Cells(cell2.Row, 10)).Copy _
Destination:=wsh1.Cells(cell1.Row, 2)


End If

Next cell2

End With


End If

Next wbk1
Next cell1

End Sub


I'm trying to figure out the right way of writing this idea, I need some help!
! Ok we start off in wrkbk A and start in cell A1(which is an invoice #) we

[quoted text clipped - 3 lines]
and repeat. Oh yeah when it's searching for content of cell A1 the invoice #
may be in wrkbk B,C or D... any ideas?


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200703/1