I’ve been searching the internet and I cannot seem to figure out my problem. Any help would be much appreciated. My code is as follows:
Private Sub removebutton_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim removebox As String
Set ws = Worksheets("Sheet2")
removebox = InputBox("Please Scan the Barcode to be added", "Add Coin", "Scan Barcode Here")
'Find the next blank row'
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'Promt User To Actually input data if they have not entered anything'
If Trim(Me.removebox.Value) = "" Then
Me.removebox.SetFocus
MsgBox "Please enter barcode"
Exit Sub
End If
'For 20 digit barcodes split into 4 parts and record the data in the next blank row'
If Len(removebox) = 20 Then
Dim s1 As String
s1 = removebox.Substring(1, 6)
Dim s2 As String
s2 = removebox.Substring(7, 8)
Dim s3 As String
s3 = removebox.Substring(9)
Dim s4 As String
s4 = removebox.Substring(10, 20)
ws.Cells(iRow, 1).Value = Me.s1.Value
ws.Cells(iRow, 2).Value = Me.s2.Value
ws.Cells(iRow, 3).Value = Me.s3.Value
ws.Cells(iRow, 4).Value = Me.s4.Value
'For 18 Digit barcodes spilt into 3 parts and record the data in the next blank row'
ElseIf (removebox) = 18 Then
Dim s5 As String
s5 = removebox.Substring(1, 6)
Dim s6 As String
s6 = removebox.Substring(7, 8)
Dim s7 As String
s7 = removebox.Substring(9, 18)
ws.Cells(iRow, 1).Value = Me.s5.Value
ws.Cells(iRow, 2).Value = Me.s6.Value
ws.Cells(iRow, 3).Value = Me.s7.Value
'If not 20 or 18 digit then it is 16, split into 3 parts and record the data in the next blank row'
Else
Dim s8 As String
s8 = removebox.Substring(1, 6)
Dim s9 As String
s9 = removebox.Substring(7, 8)
Dim s10 As String
s10 = removebox.Substring(9, 16)
ws.Cells(iRow, 1).Value = Me.s8.Value
ws.Cells(iRow, 2).Value = Me.s9.Value
ws.Cells(iRow, 3).Value = Me.s10.Value
End If
End Sub
So I messed up and the entire Code was supposed to be to remove an item and instead it adds an item I realize that. My problem is that the s1 = removebox.Substring(1, 6) highlights the removebox variable and tells me Compiler Error: Invalid Qualifier. If anyone could give me a possible solution, I know I’m doing something wrong but as you scan a bar code it comes in as 20, 18, or 16 digit integer but I need to save the parts separately in order to create an easy look-up function for the database.
Thank you in advance for any help or suggestions.
Head of Catering beat me to it. But I will paste the code since I already worked on it.
Note: Based on above, I am not breaking it into 4 equal parts. I have simply converted your existing code.