+ Reply to Thread
Results 1 to 5 of 5

VBA Match or Find code

  1. #1
    Registered User
    Join Date
    12-25-2004
    Posts
    61

    VBA Match or Find code

    Workbook that I need help with: http://www.hgs-auditing.com/ExampleCode.xls

    Ok, I have uploaded an example of my program. My questions today are in regards to the code in Module1, sub FillSectionCategory.

    The purpose of this code is to assign a Section # and Category # to each line in worksheet "Detail Import". When freshly imported, the this sheet does not have any data in the yellow fields. It aquires this information from the next worksheet, and the code. Each line in "Detail Import" has a Reference Number. What this code does is look at worksheet "Detail Import (Section-Category" and go through each line. The first line says that References 00319 - 00328 are Section 1, Category 1. So then it goes to the first worksheet and go to row 320 (due to the beginning Reference number, 319 + 1 row due to the header row), and places the corresponding Section/Category.

    So lets make sure this is clear: It matches up Refererence numbers using the digits in "Detail Import (Section-Category" to the ROW number in "Detail Import", NOT to the reference number assigned to the line. This works out 95% of the time because the Reference numbers are in numerical order in Detail Import. So for example, if the code needs to place a Section/Category in Reference 432, it looks at row 433 (which most of the time will be correct...row 433 will have a Reference number of 432.

    The problem now is sometimes the reference numbers in "Detail Import", some are not used. So it could go:
    00001
    00002
    00003
    00007
    00008
    00009

    If Reference 00008 is supposed to have a certain Section/Category, because of the way the code is written right now, it will not match up Reference numbers...it will place data in its corresponding ROW, and not find the reference number to match.

    How can I modify this code so that instead of finding a row number, it finds a Reference number (Range B in Detail Import).

    Thanks

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    In D2 of the yellow section, this formula will return the Section
    =SUMPRODUCT(--('Detail Import (Section-Category'!$D$2:$D$110<=$B2),(--('Detail Import (Section-Category'!$E$2:$E$110>=$B2)),'Detail Import (Section-Category'!$B$2:$B$110)
    and in E2, the category.
    =SUMPRODUCT(--('Detail Import (Section-Category'!$D$2:$D$110<=$B2),(--('Detail Import (Section-Category'!$E$2:$E$110>=$B2)),'Detail Import (Section-Category'!$C$2:$C$110)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    12-25-2004
    Posts
    61
    You're a freakin' genius!

  4. #4
    Registered User
    Join Date
    12-25-2004
    Posts
    61
    Just out of curiosity, how would I do this through the VBA Editor and not formulas in Excel?

    Also, how can I add a progress bar to this (since it is looping certain code)

    Thanks

  5. #5
    Registered User
    Join Date
    12-25-2004
    Posts
    61
    BUMP! Any help is appretiated

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1