Clear contents in User Form

zaska

Well-known Member
Joined
Oct 24, 2010
Messages
1,046
Hi ,

Code :

Code:
Private Sub btn_Emplyeelist_Click()
Dim lastrow As Long
lastrow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row + 1
Cells(lastrow, 1).Value = tb_EmpName.Value
Cells(lastrow, 2).Value = tb_EmpPosition.Value
Cells(lastrow, 3).Value = tb_EmpHireDate.Value

End Sub

I am trying to modify two things in the above code

1. Clear the contents in the input boxes before proceeding to enter the second employee name

2. Using Enter key instead of clicking the O.k Button to input the second employee details

Kindly provide your inputs

Thank you

Regards,
Zaska
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,

I tried the following to achieve the first task to clear the contents.

Code:
tb_Empname.Value      =  ""
tb_EmpPosition.Value   =  ""
tb_EmpHireDate.Value  =  ""

How do i bring the cursor to the first Text box after Entering the first employee Details and how to use Enter or Tab instead of Ok button for faster Data Entry

Thanks in Advance
 
Upvote 0
this code will clear any TextBox in your userform then Set the Emplyee name the Focus Box

Code:
Dim Ctrl As Control
For Each Ctrl In Me.Controls
    If TypeName(Ctrl) = "TextBox" Then
        Ctrl.Value = ""
    End If
Next Ctrl
tb_EmpName.SetFocus
 
Upvote 0
Hi,

Thank you ..

The first employee data is starting from Range A2 .. What changes are required to be made to get the data from Range A1.

What changes do i need to make to avoid pressing the Enter key Twice after inputting the EmpHireDate for Executing the Ok Button.

Is it possible to make the userform VBModeless . If so where should i use VBModeless option?
 
Upvote 0
I changed the line

lastrow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row + 0

and found the answer to my first question and i am still unable to find solution for other two queries
 
Upvote 0
I found Answer to the Second question too

Code:
Sub employeelist()
UserForm1.Show vbModeless
End Sub

Can anyone kindly help me with the final query ..I.e how to avoid using the Enter key twice after Entering the EmployeeHireDate

I meant to ask whether it is possible to retrieve the cursor to EmployeeName immediately after entering the EmpHireDate without having the need to press O.k button

Thanks
 
Upvote 0
You could set the .Default property of the commandbutton to True, but then you will need to use the tab key to progress through the textboxes.
 
Upvote 0
Thank you

After making the following change the code is not working properly

lastrow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row + 0

Regards,

Trady
 
Upvote 0
Thank you

After making the following change the code is not working properly

lastrow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row + 0

Regards,

Trady

If you are referring to the code in your first post, you probably want to qualify Cells(x,x)
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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