Results 1 to 3 of 3

Help debugging a macro - Searching for a unique string and displaying results

Threaded View

  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    Queensland, Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Help debugging a macro - Searching for a unique string and displaying results

    Hi Guys,

    I'm wondering if someone is available to help me debug a macro that I'm working on.

    I'm trying to search for a unique ID from Row 2 of Column A in "G_W_P.xlsm" within multiple sheets (8) of Column A of "G&W - S&C.xlsx" and then display the result within Column B, C, D etc. (if duplicates are found) of "G_W_P.xlsm".

    The problem with my current code (which i've included below) is that the macro runs Ok, but only displays results for about 34 rows (instead of about 400). Also, the macro appears to be innacurate in that it displays the location of unique ID's where they aren't found in that worksheet, or it displays multiple occurences of the same unique ID in the same worksheet. I think it does the latter by confusing unique IDs, for example it thinks that "CBX246-1" is a second occurence of "CBX246".

    There's also a 2 other functions that I would like the macro to do.
    Firstly - I would like to have the macro open "G&W - S&C.xlsx" when I run it in "G_W_P.xlsm" without me having to have it open in the first place as I have to with my macro.
    Secondly - I would also like the macro to display the unique ID's that were searched for in "G&W - S&C.xlsx". I was hoping the macro could create a new worksheet within "G_W_P.xlsm" and display the results in Column A there.

    I've included the working sheets that I've got so far

    Thanking anyone greatly in advance for any assitance.

    The code I have so far is.......
    Sub matchItUp()
    Dim wb1 As Workbook, wb2 As Workbook, sh As Worksheet, ws As Worksheet, lr As Long
    Dim c As Range, rng As Range, r As Range, Blr As Long
    Set wb1 = Workbooks("G_W_P.xlsm")
    Set wb2 = Workbooks("G&W - S&C.xlsx")
    Set sh = wb1.Sheets(1)
    lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
    Set rng = sh.Range("A1:A" & lr)
    For Each c In rng
    i = 1
    For Each ws In wb2.Sheets
    wlr = ws.Cells(Rows.Count, 1).End(xlUp).Row
    Set wRng = ws.Range("A2:A" & wlr)
    For Each r In wRng
    If r = c Then
    If sh.Range("B1") = "" Then
    Blr = 1
    Else
    Blr = sh.Cells(Rows.Count, 2).End(xlUp).Row + 1
    End If
    i = i + 1
    sh.Cells(Blr, i) = wb2.Name & "-" & ws.Name
    End If
    Next
    Next
    Next
    End Sub
    Attached Files Attached Files
    Last edited by arlu1201; 04-07-2012 at 03:27 AM.

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