Advertisement
Guest User

Cool thing for Jack

a guest
Sep 6th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Button1()
  2.     ' TODO: Set the active cell where it says "here" loads
  3.    ' Then find the row of the active cell
  4.    ' https://excel-macro.tutorialhorizon.com/vba-excel-select-and-activate-cells-activate/
  5.    ' https://stackoverflow.com/questions/43654157/how-to-find-cell-containing-string-in-entire-worksheet
  6.    ' https://www.mrexcel.com/forum/excel-questions/68015-return-row-number-active-cell.html
  7.  
  8.  
  9.     On Error GoTo Whoops
  10.    
  11.     Dim errorCode As Integer ' So that we can handle the error
  12.    Dim barcodeNum As String
  13.    
  14.     Dim tempItemStr As String
  15.     Dim displayString As String ' Just to tell the customer what is happening
  16.    displayString = ""
  17.    
  18.     Do
  19.         ' Take input & check number
  20.        barcodeNum = InputBox("Scan barcode now. " + vbCrLf + "Click okay or press enter when the number" + vbCrLf + "appears in the box", "New Scan")
  21.         If (!IsNumeric(barcodeNum)) Then
  22.             errorCode = 1
  23.             GoTo Whoops
  24.         End If
  25.        
  26.        
  27.        
  28.         ' Find the thing and return some values here please
  29.        
  30.         ' 1. Finds the cell containing that string
  31.        Dim rngFound As Range
  32.        
  33.         ' When we rename the sheet, change sheet1 to something else
  34.        With Worksheets("Sheet1").Cells
  35.            
  36.             Set rngFound = .Find(barcodeNum, LookIn:=xlValues)
  37.             If Not rngFound Is Nothing Then
  38.                 ' HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE HERE
  39.                
  40.             Else
  41.                 errorCode = 404
  42.                 GoTo Whoops
  43.                
  44.             End If
  45.         End With
  46.        
  47.        
  48.         ' Then add it to the string please
  49.        displayString = displayString + tempItemStr
  50.        
  51.        
  52.         ' Put this into an inputBox and take response please
  53.        
  54.        
  55.     Loop While True
  56.    
  57.    
  58.    
  59. Whoops:
  60.     ' Handle error here
  61.    If (errorCode = 0) Then
  62.         MsgBox "Complete", , "Complete"
  63.     End If
  64.    
  65.     MsgBox "Something went wrong ", , "Error: " + errorCode
  66.     ' 1 = invalid input (string)
  67.    ' 404 = not found
  68.  
  69. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement