Results 1 to 12 of 12

Thread: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Resolved HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    HTML Code:
    for EACH row in WORK
    {
       for each row in DATA
       {
        if ((WORK.row.zip == DATA.row.zip) && (WORK.row.name == DATA.row.name))
        Then
        Highlight current WORK.row to YELLOW, break out of current for loop
        ELSE
        next DATA row++
       }
        next WORK row++
    }
    [/SIZE]

    [SIZE="3"](see below for explaination)

    I have a Excel workbook called FIRSTAM8.xls

    Inside I have two seperate worksheets: 1)'DATA' & 2)'WORK'
    There are 31886 rows in sheet 'WORK' & 5741 rows in sheet 'DATA'

    Column 'C' in 'WORK' contains the customer name, Column 'B' contains the zip code.

    In the 'DATA' sheet Column 'H' contains the customer name, & Column 'S' the zip code.


    I want to compare (individually, one-by-one) the zip && name Columns ('B' & 'C')
    of each row in sheet 'WORK' to/with/against the respective
    zip && name Columns ('S' & 'H') of EACH AND EVERY row in sheet 'DATA'.

    For example: if BOTH the zip &&and&& name columns of row1 of sheet 'WORK' matches
    with ANY (any of the 5741) rows of sheet 'DATA' then row1 IS a match/hit,
    and the entire row1 of sheet 'WORK' is highlighted yellow to indicate the match status.
    If row1 of 'WORK' matches to multiple rows of 'DATA' that is okay, it is still highlighted.
    However if row1 of 'WORK' does not match (by the criteria of zip && name) to ANY of the
    5741 rows in "DATA" then it is not highlighted and the next row (row2) is processed.

    Note: When comparing names, I really mean comparing the first
    character of the customer name fields. I do this to avoid
    false negatives and so not to miss a potential match.
    This will entail using the substring manipulation functions.(?LEFT)

    --------------------

    HTML Code:
    for EACH row in WORK
    {
       for each row in DATA
       {
        if ((WORK.row.zip == DATA.row.zip) && (WORK.row.name == DATA.row.name))
        Then
        Highlight current WORK.row to YELLOW, break out of current for loop
        ELSE
        next DATA row++
       }
        next WORK row++
    }

    *OR*

    HTML Code:
    for each row in WORK
    {
       for each row in DATA
       {
        if ((WORK.row.column(B) == DATA.row.column(S)) && (WORK.row.firstcharof(column(C) == DATA.row.firstcharof(column(H)))
        Then
        Highlight.interior.current.WORK.row = YELLOW, break out of current for-loop
        ELSE
        next DATA row++
       }
        next WORK row++
    }

    CAN SOMEONE TRANSLATE THE ABOVE INTO REAL EXCEL CODE FOR ME??



    Here is a link to the ENTIRE post I made (for clarity and reference):
    http://www.ozgrid.com/forum/showthread.php?t=49941

    Here is an abridged IMAGE of the my Excel Workbook:
    Attachment 4703

    Here is the original file I am working on (LARGE):
    FIRSTAM8.xls
    http://www4.sendthisfile.com/d.jsp?t...Oeb2puKBql1LmB

    Thanks,
    Bo
    Last edited by bxc2739; Apr 28th, 2006 at 11:06 AM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    yes.. but u only want the first letter of the customer name checked?? u will get tons of false positives?? (Or did I missunderstand) u need to match them one to one..
    CASE can be ignored... so Company1 will = COMpAnY1
    is that ok??
    BRB with code...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    also.. must the Name and Zip match on the same row?
    or can u find a name match in row 7 and a zip match in ro 12 etc...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    Static, yes I do want it like that. You understood me corrects.

    The thing is, my Excel spreedsheet is 31000+ rows LONG!! And I know
    from previous spreedsheets of the similiar nature that ONLY 2-3%
    of the ENTIRE thing actually match, and the vast majority are NO match.
    So its kinda like looking for pins in a large haystack. So I will actually in my case
    not get the ton of false postives like you would invision. Therefore (since I have SO FEW actuall matchs) I want to be on the safe side and only search for
    first character.

    Thanks for the reply!!

    Bo

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    Static, what I am actually trying to do, is match customers from one sheet againts another. But since there are 31000+ to match, I try something clever, like using a macro in Excel to scan for all zip + name that do not match any records, thus I can safely eliminate them, and the rest (like 2-3%) that is left over, I will go back and match/verify them by hand.

    Here take a look at this thread, it will explain in detial everything.

    http://www.ozgrid.com/forum/showthread.php?t=49941

    Thanks!

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    Why not use a vlookup in excel? That way you wouldn't need any code.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    Dkenny,

    I would, but except my case is more complicated.

    I have two sheets in a workbook. BOTH VERY LARGE.
    The zip code column and customer name column of EACH row in sheet2
    has to be compared with the repsective zip && name column EVERY row in
    sheet1. (am I making sense? thats 31000*5000*2=310000000 total comparisons.)

    This thread explains in FULL detial (sorry, its very long thread I wrote)
    http://www.ozgrid.com/forum/showthread.php?t=49941

    ANd additional, when I need to search by name, actually I am
    wanting to search by the first character of the customer name fields,
    thus this entials substring manipulation.

    So because of these many factors, I don't think something this complexed can be implemented as a formula, but really needs a macro code.


    Thanks,
    Bo

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    VB Code:
    1. Private Sub HighLightMatches()
    2.     Dim WORKsht As Worksheet
    3.     Dim DATAsht As Worksheet
    4.     Dim wRow As Long
    5.     Dim dRow As Long
    6.    
    7.     Set WORKsht = ActiveWorkbook.Sheets("WORK")
    8.     Set DATAsht = ActiveWorkbook.Sheets("DATA")
    9.    
    10.     wRow = 1
    11.     'this asumes there are no blank rows
    12.     Do Until WORKsht.Cells(wRow, 2) = ""  'go till the first empty space is found
    13.         dRow = 1
    14.         Do Until DATAsht.Cells(dRow, 8) = "" 'go till the first empty space is found
    15.             If UCase(Left(WORKsht.Range("C" & wRow), 1)) = UCase(Left(DATAsht.Range("H" & dRow), 1)) And WORKsht.Range("B" & wRow) = DATAsht.Range("S" & dRow) Then
    16.                 Rows(wRow & ":" & wRow).Select
    17.                 With Selection.Interior
    18.                     .ColorIndex = 36
    19.                     .Pattern = xlSolid
    20.                 End With
    21.                 Exit Do
    22.             End If
    23.             dRow = dRow + 1
    24.         Loop
    25.         wRow = wRow + 1
    26.     Loop
    27.        
    28.  
    29. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    It can be managed with formulas. Add a column to each table that concatenates the values you need to compare into a single string and then do lookups between those 2 columns.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    Static,

    thanks for the QUICK response with the code! Wow that was fast!

    I'm still running it on my computer (still computing) (this might take a while...)
    and I'll let you know how it did when it is done!

    THanks again!

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    Thanks Static, that is wonderful code, it works great!

    I tested it on smaller files and estimated the time.
    However it will take 6.5 hours, so I will see the full results tomorrow.

    Thanks!

    Bo

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    25

    Re: HELP!!! Could someone HELP TRANSLATE this simple psuedo code into MACRO please?!

    Static, it actually took 3 hours to execute the entire sheet, but it worked

    Thanks so much, that is wonderful little code!!

Posting Permissions

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



Click Here to Expand Forum to Full Width