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
 

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.
How about something like:

code = " "
Do While code <> ""
code = InputBox("Please scan a barcode and hit enter if you need to")
Loop
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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