Input Box is Not working

bobsburgers

Board Regular
Joined
Jun 25, 2017
Messages
60
Hi, all -

I'm having difficulty with the second InputBox in my code.

Ideally when asked for the "Employee ID Number," the user would scan a barcode to populate a corresponding cell in Column C; however, although I can get the scanner to read and recognize the barcode on the ID cards, the ID number does not populate its respective cell.

The macro then loops back to the search function, as planned.

Here's the code I'm working with:

Code:
Sub iPad_SignOut()

    Dim scanstring As String
    Dim foundscan As Range
    Dim ws As Worksheet
    Dim foundscan_address As String
    Dim myValue As Variant
    
Set ws = ActiveSheet

scanstring = InputBox("Please enter a value to search for", "Enter value")
If scanstring = "" Then Exit Sub

With ws.Columns("A")
    
    Set foundscan = .Find(What:=scanstring, LookIn:=xlValues, LookAt:=xlWhole, _
                          SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                          MatchCase:=False, SearchFormat:=False)
                      
    If Not foundscan Is Nothing Then
foundscan_address = foundscan.Address

Do
        foundscan.Offset(0, 1).Value = Now
        ws.Activate
        foundscan.Activate
        ActiveWindow.ScrollRow = foundscan.Row
        Set foundscan = .FindNext(foundscan)
        ActiveCell.Offset(0, 2).Activate
        myValue = InputBox("Please enter Employee ID Number", "Enter value")
   

Loop While Not foundscan Is Nothing And foundscan.Address <> foundscan_address
    
    
    Else
        MsgBox scanstring & "  was not found"
    End If
    
End With

    Call iPad_SignOut

End Sub

Please let me know if you can catch my mistake(s)! haha

Best,
bob
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You have recursion there by calling the sub again at the end. I've also refactored the code a little and indented it properly. I haven't tested this thoroughly but it seems to be working:

Code:
Sub iPad_SignOut()

Dim scanstring As String
Dim foundscan As Range
Dim ws As Worksheet
Dim foundscan_address As String
    
Set ws = ActiveSheet

Do While True
    scanstring = InputBox("Please enter a value to search for", "Enter value")
    If scanstring = "" Then Exit Do
    
    With ws.Columns("A")
        Set foundscan = .Find(What:=scanstring, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If foundscan Is Nothing Then
            MsgBox scanstring & "  was not found"
        Else
            foundscan_address = foundscan.Address
            Do
                foundscan.Offset(0, 1).Value = Now
                ws.Activate
                foundscan.Activate
                ActiveWindow.ScrollRow = foundscan.Row
                ActiveCell.Offset(0, 2).Activate
                foundscan.Offset(0, 2).Value = InputBox("Please enter Employee ID Number", "Enter value")
                Set foundscan = .FindNext(foundscan)
            Loop While Not foundscan Is Nothing And foundscan.Address <> foundscan_address
        End If
    End With
Loop

End Sub

WBD
 
Upvote 0
Thank you so much WBD!

I've tested it with our equipment and everything seems to be working great!

Also, thank you very much for showing me a more appropriate way to go about this! I'm still learning (thanks in large part to this site! haha)

best,
bob
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top