Return to Command Button after entering data

RoxanneF

New Member
Joined
Nov 22, 2017
Messages
3
Is there a way to return to a CommanButton after entering data? I am matching a barcode to a column of data, it automatically moves to the next column and enters a time/date stamp then moves to the next column for manually entering a sample weight. After entering the sample weight, I would like to return to the CommandButton to scan the next barcode.
This is what I have thus far:
Private Sub CommandButton1_Click()
Dim code AsVariant
Dim matchedCell AsRange
' set up errorhandling
On Error GoToBadEntry

code =InputBox("Please scan a barcode and hit enter if you need to")

' Exit ifcancelled
If code ="" Then Exit Sub

Set matchedCell =Range("B2:B1000").Find(what:=code, LookIn:=xlValues, lookat:=xlWhole,MatchCase:=True)
If Not matchedCellIs Nothing Then matchedCell.Offset(0, 1).Value = Now
matchedCell.Offset(, 2).Select
Exit Sub
 

eikogs

New Member
Joined
Aug 12, 2016
Messages
23
How about something like:

code = " "
Do While code <> ""
code = InputBox("Please scan a barcode and hit enter if you need to")
Loop
 

RoxanneF

New Member
Joined
Nov 22, 2017
Messages
3
Thank you, getting closer. The CommandButton is opening but too soon. The time and date stamp is entered but I am not able to enter the data before the commandbutton opens. I need the commandbutton to open after I enter data in the column next to the time and date stamp and I hit enter. Here is what I have at this point:
Private Sub CommandButton1_Click()
Dim code As Variant
Dim matchedCell As Range

' set up error handling

On Error GoTo BadEntry
code = " "
Do While code <> ""
code = InputBox("Please scan a barcode and hit enter")

' Exit if cancelled

If code = "" Then Exit Sub

Set matchedCell = Range("B2:B1000").Find(what:=code, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=True)
If Not matchedCell Is Nothing Then matchedCell.Offset(0, 1).Value = Now
matchedCell.Offset(, 2).Select
Loop
Exit Sub
 

Forum statistics

Threads
1,081,676
Messages
5,360,441
Members
400,586
Latest member
Minty

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top