Quote:
|
Originally Posted by davemeyer1
Where I am running into confusion is the fact that the user is able to specify multiple workbooks so my code has to consider which workbook(s) the user specified in step 1, then search them for a specific field (say customer name) and return data on just those customers. I'd also like to allow flexibility so the user can search based on a different criteria (say zip code).
|
There are a couple ways of going about this. (1) if the user is specifying workbooks in a multi-select getopenfile dialog the results are returned in an Array. You can retain the array data in a Global Variable or by writing it to a location, text file or hidden workbook. (2) suppose you want to check all the open workbooks. You can use a loop to check each book.
Code:
For each wBook in Workbooks
With wBook.Worksheets(1)
If .Cells(1,1) = "Customer Name" Then
strName = .Cells(2,1)
' Next Add the name to your list
End If
End With
Next
A good idea for something like this is to use a Named Range to contain the data in your workbooks. Then if you are search for data in several books by a named range you can still find it if the position varies from book to book. Although if you call a named range where the range does not exist you will produce an error. you must handle the error unless you are 100% sure the named range is always going to exist.
If this is going to be a frequent process, you may want to consolidate this data into an index file or a database table where you can search all the data in a single location.