Help with Userform

rhino4eva

Active Member
Joined
Apr 1, 2009
Messages
260
Office Version
  1. 2010
Platform
  1. Windows
VBA Code:
Private Sub CommandButton1_Click()
    Dim txtLabNo        As Variant, m As Variant
    Dim i               As Long
    Dim wsMaster        As Worksheet
   'lab number
    txtLabNo = Left(Me[COLOR=rgb(209, 72, 65)].[/COLOR][COLOR=rgb(65, 168, 95)]LabNumBOX[/COLOR], 7)
     If Not IsNumeric(txtLabNo) Then Exit Sub Else txtLabNo = Val(txtLabNo)
   'change master sheet name as required
    Set wsMaster = ThisWorkbook.Worksheets("DATA")
   'search column A
    m = Application.Match(txtLabNo, wsMaster.Columns(2), 0 
    If Not IsError(m) Then
            'post to master sheet
            wsMaster.Cells(CLng(m), 4).Value = "x"
            Me.LabNumBOX = ""
            LabNumBOX.SetFocus
    Else
   'inform user
        MsgBox txtLabNo & Chr(10) & "Record Not Found", 48, "Not Found"
           End If
   End Sub


So i have a userform that searches for a a Lab number in a Column A given the text in a Userform text box(LabNumBOX)
This lab number is from a bar code reader that has a carriage return as a default. The code above actioned by pressing a button.
How can i get the textbox to run automatically without having to press the button
 
however, i cant get it to move on to the cell below... it just changes the content of Cells(5,2) .... i want to repeat an unknown number for bar-codes into 6,2 7,2 etc.
Untested:
VBA Code:
Private Sub TextBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If KeyCode = Asc(vbCr) Then
    With Sheets("DATA")
        n = .Range("B" & Rows.Count).End(xlUp).Row
        If n < 5 Then n = 5
        .Cells(n, 2).Value = Left(Me.TextBox2, 7)
        Me.TextBox2.Value = ""
    End With
End If

End Sub
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
thanks for that ... after a slight modification a got it to work(y)

Private Sub TextBox2_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If KeyCode = Asc(vbCr) Then
With Sheets("DATA")
n = .Range("B" & (Rows.Count)).End(xlUp).Row
n = n + 1
.Cells(n, 2).Value = Left(Me.TextBox2, 7)
.Cells(n, 3).Value = "x"
Me.TextBox2.Value = ""
End With
End If

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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