Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Better methodology to search two Microsft Excel worksheet.

Status
Not open for further replies.

jimbo6464

Technical User
Jan 3, 2007
1
US
Inquiring; if there better methodology to search two worksheet. Background, I have written a macro to basically merge to worksheet. There is one to many relationships with the two worksheets; worksheet ‘A’ contains the summary record; worksheet ‘B’ has the detail records.

The macro reads a row in the worksheet ‘A’ creates a key from specific columns from worksheet ‘A’ then commencing with the first record in worksheet ‘B’ creates a key for each row in worksheet ‘B’ then compares the keys looking for match; reads the entire worksheet.

There are two do loops; the first is for worksheet ‘A’ and second is for worksheet ‘B’; I am sure thru logic; I could reduce the records that are read using the do loops.

The question I am asking; are their methodology in Microsoft Excel VBA that could be employ to improve the search the worksheet ‘B’; rather read the each record.

Example; build an index for both worksheets then used the index to locate the record.

Thanks in advance for response to the inquiry

Jim
 




Hi,

I need some clarification.

You stated, "I have written a macro to basically merge to worksheet."

You are merging two worksheets, into what? One worksheet? That's generally not a good idea as each worksheet can function as a separate table within the workbook.

Have you checked out Excel's lookup functions? I most often, use INDEX and MATCH together...
Code:
vOffset = application.match(lookupvalue, lookuprange, 0)
if not iserror(vOffset) then
  finalvalue = application.index(finalrange, voffset,1)
end if


Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top