Minimum value in textbox

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
172
Hi, can anybody help I am trying to set a minimum value when scanning a barcode in to a textbox to a minimum of 47 digits so if a barcode is scanned with less than 47 digits it will error but I can not get it to work. below is the vba I am using now which works fine for scanning but it excepts barcodes with less than 47 digits I have tried using if len(textbox2.value) <> 47 with now joy.

Private Sub textbox2_Change()
Dim erow As Long
If Len(TextBox2.Value) = 47 Then
Application.DisplayAlerts = False
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1) = TextBox1.Text
Cells(erow, 2) = TextBox2.Text
Cells(erow, 7) = TextBox3.Text
Cells(erow, 6) = TextBox4.Text
Range("H" & Rows.Count).End(xlUp).Offset(1).Value = Now
Cells(erow, 3).FormulaR1C1 = "=mid(rc[-1],4,4)"
Cells(erow, 4).FormulaR1C1 = "=mid(rc[-2],8,4)"
Cells(erow, 5).FormulaR1C1 = "=mid(rc[-3],30,6)"
Range("A1").End(xlDown).Select
TextBox2.Text = ""
TextBox3.Text = ""
TextBox2.Visible = True
TextBox4.Text = ""
TextBox1.Visible = True
TextBox3.Visible = False
TextBox4.Visible = False
Label3.Visible = False
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Application.DisplayAlerts = True
TextBox2.SetFocus
End If
End Sub
1584441562230.png


Regards
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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