Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:40:38+00:00 2026-06-02T17:40:38+00:00

I’ve been searching the internet and I cannot seem to figure out my problem.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:40:40+00:00Added an answer on June 2, 2026 at 5:40 pm

    Head of Catering beat me to it. But I will paste the code since I already worked on it.

    A bar code it comes in as 20, 18, or 16 digit integer

    Note: Based on above, I am not breaking it into 4 equal parts. I have simply converted your existing code.

    Option Explicit
    
    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")
    
        '~~> Prompt User To Actually input data if they have not entered anything
        If Len(Trim(removebox)) = 0 Then
            MsgBox "Please enter barcode", vbCritical, "Please Try again"
            Exit Sub
        End If
    
        '~~> Find the next blank row
        iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
        SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
    
        ws.Cells(iRow, 1).Value = Left(removebox, 6)
        ws.Cells(iRow, 2).Value = Mid(removebox, 7, 8)
    
        Select Case Len(removebox)
            '~~> For 20 digit barcodes split into 4 parts and record
            '~~> the data in the next blank row'
            Case 20
                ws.Cells(iRow, 3).Value = Mid(removebox, 9)
                ws.Cells(iRow, 4).Value = Mid(removebox, 10, 20)
            '~~> For 18 Digit barcodes spilt into 3 parts and record
            '~~> the data in the next blank row'
            Case 18
                ws.Cells(iRow, 3).Value = Mid(removebox, 9, 18)
            '~~> If not 20 or 18 digit then it is 16, split into 3
            '~~> parts and record the data in the next blank row'
            Case Else
                ws.Cells(iRow, 3).Value = Mid(removebox, 9, 18)
        End Select
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.