+ Reply to Thread
Results 1 to 8 of 8

Macro that Matches Scanned Data

Hybrid View

  1. #1
    Registered User
    Join Date
    07-30-2020
    Location
    Charleston, SC
    MS-Off Ver
    Office 365
    Posts
    30

    Question Macro that Matches Scanned Data

    I have a project that takes data scanned in and matches it together as a check in/check out type system. In the example attachment, I need the scanned data in sheet 2 to populate the respective rows and columns in sheet 1. Basically, when a Tray ID is scanned, I need it to either populate row 3 or 6, depending on whether that tray is checked out or not. For example, when a tray ID has been scanned an odd number of times, I need it to start a new row, as it's being checked out, etc. I'm trying to find a macro that either:
    • Takes the scanned in data on Sheet 2, puts it in its place and matches it in sheet 1.
    • Places the scanned data where it belongs in Sheet 1 in the first place, matching Tray IDs as it's entered.
    I sincerely appreciate any insight you can provide for me here.
    Attached Files Attached Files
    Last edited by singinwes; 08-17-2020 at 12:47 PM. Reason: Solved

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro that Matches Scanned Data

    Possibly...
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim lRow As Long, rg As Range, c As Range
        Dim b As Boolean, s As String
    
        If Target.Column > 1 Then Exit Sub
        
        b = False
        lRow = Sheet1.Cells(Rows.Count, 3).End(xlUp).Row
        Set rg = Sheet1.Range("C6:C" & lRow)
        With rg
            Set c = .Find(Target.Value, Cells(6, 3))
            If Not c Is Nothing Then
                s = c.Address
                Do
                    If c.Offset(, 3) = vbNullString Then
                        c.Offset(, 3) = Target.Value
                        c.Offset(, 4) = Now()
                        b = True
                    Else
                        Set c = .FindNext(c)
                    End If
                Loop Until c.Address = s
            Else
                b = True
                
            End If
            If b = False Then
                Sheet1.Cells(lRow + 1, 3) = Target.Value
                Sheet1.Cells(lRow + 1, 4) = Now()
            End If
        End With
    End Sub
    ...placed in sheet2 code module.

  3. #3
    Registered User
    Join Date
    07-30-2020
    Location
    Charleston, SC
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Macro that Matches Scanned Data

    Well I just realized I said row 3 and 6 instead of column 3 and 6. I'm using R1C1 because my employer requires it. Sorry for the confusion. This looks promising, but I'm not sure what I need to update to resolve my mistake.

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro that Matches Scanned Data

    See the attached file..
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-30-2020
    Location
    Charleston, SC
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Macro that Matches Scanned Data

    Oh nice, you saw through my initial mistake! This is great and is so close to what I need. It's filling in column 6 when it matches a pre-filled column 3, but it isn't doing the initial "scan in." For example, if sheet 1 is empty and I enter a 4 on sheet 2, I need it to fill out out column 3 on sheet 1 with that unmatched 4 on the next "empty" row. Does that make sense? This is extremely helpful, thank you for your help so far!

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro that Matches Scanned Data

    Try this...
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim lRow As Long, rg As Range, c As Range
        Dim b As Boolean, s As String
    
        If Target.Column > 1 Then Exit Sub
        
        b = False
        lRow = Sheet1.Cells(Rows.Count, 3).End(xlUp).Row
        Set rg = Sheet1.Range("C6:C" & lRow)
        With rg
            Set c = .Find(Target.Value, Cells(6, 3))
            If Not c Is Nothing Then
                s = c.Address
                Do
                    If c.Offset(, 3) = vbNullString Then
                        c.Offset(, 3) = Target.Value
                        c.Offset(, 4) = Now()
                        b = True
                    Else
                        Set c = .FindNext(c)
                    End If
                Loop Until c.Address = s
            End If
            If b = False Then
                Sheet1.Cells(lRow + 1, 3) = Target.Value
                Sheet1.Cells(lRow + 1, 4) = Now()
            End If
        End With
    End Sub
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    07-30-2020
    Location
    Charleston, SC
    MS-Off Ver
    Office 365
    Posts
    30

    Re: Macro that Matches Scanned Data

    That's absolutely perfect, thank you so much for your help!

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,308

    Re: Macro that Matches Scanned Data

    You're welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 05-29-2018, 01:20 PM
  2. Guidance with Barcode Scanned Sales Recon Macro
    By Sintek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2017, 01:49 PM
  3. Vba to enter scanned Data into Column Depending on what is scanned.
    By JRidge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-10-2014, 08:20 AM
  4. How to automatically sort Scanned data to excell
    By JoeGellar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-07-2013, 02:06 PM
  5. Controlling scanning and naming of a scanned document ipdf from within an Excel macro
    By Tumushabe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2012, 02:15 PM
  6. Auto Enter After Data is Scanned
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-02-2008, 01:52 PM
  7. Importing scanned data
    By Jack Sheet in forum Excel General
    Replies: 7
    Last Post: 07-18-2006, 07:20 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