How to Data Entry by UserForm Using Excel VBA Easily

Welcome to Excel Avon

DATA ENTRY BY USERFORM

DOWNLOAD USED EXCEL FILE FROM HERE>>

Visual Basic is an excellent language for automating repetitive tasks in Excel. Imagine taking your automation up a notch by creating highly functional Userform that also look clean for end users. Data Entry Form is a form that helps to enter the data with the help of a form in which the data can be added, searched, and previous data can be deleted. Data entry in Excel without forms can be very time-consuming. 

Data entry by Userform in Excel helps overcome all these limitations and makes the task of entering data less time-consuming and less error-prone. In this article, let us see how to do data entry By UserForm using Excel VBA.

DATA ENTRY BY USERFORM USING EXCEL VBA

Well, you should know how to create a Data Entry by UserForm, because in the previous article we introduced you to UserForm and told you how to insert UserForm in VBE. And how to insert label and text box in it and let’s understand. For how to do data entry by UserForm, we have to go like last time, first go to Developer Tab then click on Visual Basic’s Option as shown in the image below.

sort-data-on-excel-using-VBA

On opening in VBE, you have to go to Insert and then UserForm has to be inserted, as can be seen in the image.

introduction-of-userform

When we click on the UserForm, a separate wizard box will be created in a window VBE, in which you can see UserForm1 as the default name.

introduction-of-userform.png

Now let’s make some changes like first of all we will change the name and caption of the UserForm1.

DATA ENTRY BY USERFORM IN EXCEL VBA

Now we will select the label from the Toolbox and then insert the label into the UserForm.

DATA ENTRY BY USERFORM IN EXCEL VBA1

Drag the label, we will insert as many labels as there are properties. After inserting the label in UserForm we will name the label as.

DATA ENTRY BY USERFORM IN EXCEL VBA2

Now we will insert the text box in the UserForm, 

DATA ENTRY BY USERFORM IN EXCEL VBA3

Click textbox and change the name of the text box for Name Column. Similarly, we will change the name of all the text boxes.

DATA ENTRY BY USERFORM IN EXCEL VBA (2

Now we’ll add a command button in UserForm, with this we Rename Command Button ‘Submit‘ and ‘Close‘.

DATA ENTRY BY USERFORM IN EXCEL VBA4 (2)

Double click on close button, Double clicks on close button then we will create code for close button unload.me will use.

Private Sub CommandButton2_Click()
Unload Me
End Sub

Double click on Submit button. and Define Variables.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long
End Sub

Set worksheet as Activesheet, here we’ll Declare Last row.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long

set ws = Activesheet
lr = WS.Range("A" & Rows.Count).End(xlUp).Row + 1
End Sub

Now we will create the range to fill the names in the worksheet.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long

set ws = Activesheet
lr = WS.Range("A" & Rows.Count).End(xlUp).Row + 1

WS.Range("A" & lr).Value = Me.txtName.Value
End Sub

Copy and paste Text Boxes code. and change cell.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long

set ws = Activesheet
lr = WS.Range("A" & Rows.Count).End(xlUp).Row + 1

WS.Range("A" & lr).Value = Me.txtName.Value
WS.Range("B" & lr).Value = Me.txtName.Value
WS.Range("C" & lr).Value = Me.txtName.Value
WS.Range("D" & lr).Value = Me.txtName.Value
WS.Range("E" & lr).Value = Me.txtName.Value

End Sub

And then Change Text Boxes Name.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long

set ws = Activesheet
lr = WS.Range("A" & Rows.Count).End(xlUp).Row + 1

WS.Range("A" & lr).Value = Me.txtName.Value
WS.Range("B" & lr).Value = Me.txtDOB.Value
WS.Range("C" & lr).Value = Me.txtGender.Value
WS.Range("D" & lr).Value = Me.txtPhone.Value
WS.Range("E" & lr).Value = Me.txtEmail.Value
End Sub

We will write the code to clear the textbox once the value is filled to worksheet. copy and paste that code and change text boxes names.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long

set ws = Activesheet
lr = WS.Range("A" & Rows.Count).End(xlUp).Row + 1

WS.Range("A" & lr).Value = Me.txtName.Value
WS.Range("B" & lr).Value = Me.txtDOB.Value
WS.Range("C" & lr).Value = Me.txtGender.Value
WS.Range("D" & lr).Value = Me.txtPhone.Value
WS.Range("E" & lr).Value = Me.txtEmail.Value

Me.txtName.Value = ""
Me.txtDOB.Value = ""
Me.txtGender.Value = ""
Me.txtPhone.Value = ""
Me.txtEmail.Value = ""
End Sub

Now we will use the message box ‘Data Submit Successfully’ with VbInformation sign.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long

set ws = Activesheet
lr = WS.Range("A" & Rows.Count).End(xlUp).Row + 1

WS.Range("A" & lr).Value = Me.txtName.Value
WS.Range("B" & lr).Value = Me.txtDOB.Value
WS.Range("C" & lr).Value = Me.txtGender.Value
WS.Range("D" & lr).Value = Me.txtPhone.Value
WS.Range("E" & lr).Value = Me.txtEmail.Value

Me.txtName.Value = ""
Me.txtDOB.Value = ""
Me.txtGender.Value = ""
Me.txtPhone.Value = ""
Me.txtEmail.Value = ""
MsgBox "Data submitted successfully!", vbInformation
End Sub

Go to the Activesheet. And Click on Insert Icon Select a button. Drag on Worksheet .

DATA ENTRY BY USERFORM IN EXCEL VBA5

We have not yet created the macro which will show the Dataform then now we will go to VBE to create the macro then firstly go to the insert tab then insert the module. do data entry by UserForm with Excel VBA.

Sort-data-on-excel-using-vba

Once the module is inserted, and we’ll write a subroutine to Sub Open Form. Macro has been created which will only show the data form in the sheet.

Sub OpenForm()
DataForm.Show
End Sub

Now open worksheet. and we’ll assign Macro. Select macro and click Ok.

DATA ENTRY BY USERFORM IN EXCEL VBA5.png

Now click on the insert button. The data form has been opened, now we will fill the information in it.

DATA ENTRY BY USERFORM IN EXCEL VBA7

First text box is for Name, so we’ll write the name. Similarly fill all the data. and click submit button.

DATA ENTRY BY USERFORM IN EXCEL VBA8

We will get the message of Data submitted Successfully.

DATA ENTRY BY USERFORM IN EXCEL VBA8.png

Now Close UserForm.

DATA ENTRY BY USERFORM IN EXCEL VBA9 (2)

Now you can see data is filled in Worksheet.

DATA ENTRY BY USERFORM IN EXCEL VBA9 (3)

So now we want to make a condition that if the name is not written in the form, then this form should not be submitted. Go to VBE and click. create a code here.

Private Sub CommandButton1_Click()
Dim WS As Worksheet
Dim lr As Long

If Me.txtName.Value = "" Then
   MsgBox "Please write the name", vbExclamation
   Exit Sub
End If
Set WS = ActiveSheet
lr = WS.Range("A" & Rows.Count).End(xlUp).Row + 1

WS.Range("A" & lr).Value = Me.txtName.Value
WS.Range("B" & lr).Value = Me.txtDOB.Value
WS.Range("C" & lr).Value = Me.txtGender.Value
WS.Range("D" & lr).Value = Me.txtPhone.Value
WS.Range("E" & lr).Value = Me.txtEmail.Value

Me.txtName.Value = ""
Me.txtDOB.Value = ""
Me.txtGender.Value = ""
Me.txtPhone.Value = ""
Me.txtEmail.Value = ""

MsgBox "Data submitted successfully!", vbInformation
End Sub

After writing the code we will go back to the worksheet. and then click on enter data button..

DATA ENTRY BY USERFORM IN EXCEL VBA7

Now if we try to submit it, it will give us a message ‘Please write the name‘. 

DATA ENTRY BY USERFORM IN EXCEL VBA11

Now we will fill the information in the UserForm and submit it, even then it will give us a message which will be like this ‘Data submitted successfully.’

DATA ENTRY BY USERFORM IN EXCEL VBA12

So now we will submit the Dataform then we will get this message.

DATA ENTRY BY USERFORM IN EXCEL VBA13

Now you can see data is filled in Worksheet.

DATA ENTRY BY USERFORM IN EXCEL VBA13.png

Therefore, I hope that you have understood How to Data Entry by UserForm Using Excel VBA, maybe if you do not understand some options, then you can comment us, which we will answer soon and for more information, you can follow us on Twitter, Instagram, LinkedIn and you can also follow on YouTube.

DOWNLOAD USED EXCEL FILE FROM HERE>>

LEARN MORE TOPIC IN VBA HERE

You can also see well-explained video here about How to Data Entry by UserForm Using Excel VBA

Leave a Reply