Mick Peters
Board Regular
- Joined
- May 18, 2015
- Messages
- 93
I am fairly new to VBA but I have some code I have made up Userfrom looking at examples. I have a form into which a user scans Name and equipment. I would like once the equipment is scanned in that the form then offloads the information to the worksheet and blanks all the text boxes on the form. The below code works with the exception that because I change the equipment box from what the user just scanned in to blank the event fires again offloading just blank cells to the worksheet. I would like to turn off the change event once it has fired until the user form is reset then turn it back on again.
As with the Application.EnableEvents = False then Application.EnableEvents = True but they don't seem to work.
Any help would be very much appreciated.
Private Sub TxtEquipment_Change()
Range("A2").Select
ActiveCell.End(xlDown).Select
LastRow = ActiveCell.Row
Cells(LastRow + 1, 1).Value = TxtDate.Text
Cells(LastRow + 1, 2).Value = TxtTime.Text
Cells(LastRow + 1, 4).Value = TxtEquipment.Text
Cells(LastRow + 1, 3).Value = TxtUser.Text
Cells(LastRow + 1, 5).Value = TxtBookedOut.Text
Cells(LastRow + 1, 6).Value = TxtUser.Text & TxtEquipment.Text
Range("A2").Select
TxtDate.Value = Date
TxtTime.Value = Time
TxtBookedOut.Value = Range("F1").Value
Application.EnableEvents = False
TxtEquipment.Text = ""
TxtUser.Text = ""
Application.EnableEvents = True
frmDatainput.TxtUser.SetFocus
End Sub
As with the Application.EnableEvents = False then Application.EnableEvents = True but they don't seem to work.
Any help would be very much appreciated.
Private Sub TxtEquipment_Change()
Range("A2").Select
ActiveCell.End(xlDown).Select
LastRow = ActiveCell.Row
Cells(LastRow + 1, 1).Value = TxtDate.Text
Cells(LastRow + 1, 2).Value = TxtTime.Text
Cells(LastRow + 1, 4).Value = TxtEquipment.Text
Cells(LastRow + 1, 3).Value = TxtUser.Text
Cells(LastRow + 1, 5).Value = TxtBookedOut.Text
Cells(LastRow + 1, 6).Value = TxtUser.Text & TxtEquipment.Text
Range("A2").Select
TxtDate.Value = Date
TxtTime.Value = Time
TxtBookedOut.Value = Range("F1").Value
Application.EnableEvents = False
TxtEquipment.Text = ""
TxtUser.Text = ""
Application.EnableEvents = True
frmDatainput.TxtUser.SetFocus
End Sub