Results 1 to 2 of 2

Evaluate Match 3 sheets continue when error (probably Loop?)

Threaded View

psjpsjpsjpsj Evaluate Match 3 sheets... 08-10-2016, 05:20 AM
LeoTaxi Re: Evaluate Match 3 sheets... 08-10-2016, 07:02 PM
  1. #1
    Registered User
    Join Date
    10-16-2013
    Location
    Nederland
    MS-Off Ver
    Excel 2003
    Posts
    38

    Evaluate Match 3 sheets continue when error (probably Loop?)

    Hello,

    In the attached Example I'm trying to get excel to fill in Sheet_B and Sheet_C with data filled in by a user in Sheet_A.

    The problem is that the code stops as soon as it cannot find a stock number in Sheet_B that is listed in Sheet_C. Also, it must be possible to make mistakes that are shown after the macro filled in the stock numbers that were found in Sheet B and C. In short:

    1. Pressing the button in sheet A fills in Sheet B and C.
    2. When it cannot find a (new) stock number it should bring up a msg box with the stock numbers that could not be found.

    This is the code I have so far:

    
    Sub The_Button()
       '
       ' The_Button Macro
       '
       Dim sh1 As Worksheet
       Dim sh2 As Worksheet
       Dim destRow, destCol
       
       With ThisWorkbook
          Set sh1 = .Sheets(1)
          Set sh2 = .Sheets(2)
          
       End With
       
       destRow = Evaluate("match(" & sh1.Name & "!b4 & " & sh1.Name _
          & "!b5, " & sh2.Name & "!a1:a500 & " & sh2.Name & "!b1:b200, 0)")
       If IsError(destRow) Then
          MsgBox ("Item/order: " & sh1.Range("B4") & "/" & sh1.Range("B5") _
             & " not found in Sheet: " & sh2.Name)
          Exit Sub
       End If
       
       lastRow = sh1.Cells(Rows.Count, 1).End(xlUp).Row
       For r = 8 To lastRow
          destCol = Evaluate("match(" & sh1.Name & "!a" & r & "," & sh2.Name & "!3:3,0)")
          If IsError(destCol) Then
             MsgBox ("Stocknumber " & sh1.Cells(r, 1) & " not found in Sheet: " _
                & sh2.Name)
             Exit Sub
          End If
       
          sh2.Cells(destRow, destCol) = sh1.Cells(r, 2)
       Next
       
    'Copied from above with
    
       Dim sh3 As Worksheet
      
       With ThisWorkbook
          Set sh3 = .Sheets(3)
          
       End With
       
       destRow = Evaluate("match(" & sh1.Name & "!b4 & " & sh1.Name _
          & "!b5, " & sh3.Name & "!a1:a500 & " & sh3.Name & "!b1:b200, 0)")
       If IsError(destRow) Then
          MsgBox ("Item/order: " & sh1.Range("B4") & "/" & sh1.Range("B5") _
             & " not found in Sheet: " & sh3.Name)
          Exit Sub
       End If
       
       lastRow = sh1.Cells(Rows.Count, 1).End(xlUp).Row
       For r = 8 To lastRow
          destCol = Evaluate("match(" & sh1.Name & "!a" & r & "," & sh3.Name & "!3:3,0)")
          If IsError(destCol) Then
             MsgBox ("Stocknumber " & sh1.Cells(r, 1) & " not found in Sheet: " _
                & sh3.Name)
             Exit Sub
          End If
       
          sh3.Cells(destRow, destCol) = sh1.Cells(r, 2)
       Next
       
    End Sub
    Thanks in advance,

    Psj
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA - How to continue inner loop while going to next iteration of outer loop?
    By alviniac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2015, 11:21 PM
  2. VBA to use evaluate with index match returns #VALUE! error
    By maym in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2015, 10:49 AM
  3. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  4. Need loop to continue instead of end
    By lordterrin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-26-2013, 07:01 PM
  5. Macro Loop Broken. Detects Max but doesn't continue loop
    By herchenbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2011, 12:17 PM
  6. Index / Match / Vlookup Loop across 3 sheets
    By NewExcelUser in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-23-2009, 03:27 AM
  7. [SOLVED] How to continue loop after deleting row?
    By joeu2004@hotmail.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-10-2006, 09:00 AM

Tags for this Thread

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