Allow Data Entry into Excel Worksheet Via User Form Only

How to Allow data Entry into an Excel Worksheet Via User-Form or Macro Only.

Here’s the complete VBA code:

Option Explicit

Private Sub cmdExit_Click()
Unload Me
End Sub

Private Sub cmdTransfer_Click()
Dim erow As Long
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1) = txtCustomerName
Cells(erow, 2) = txtMobile
End Sub

Private Sub Workbook_Open()
ActiveWorkbook.Sheets(“Sheet1″).Protect Password:=”[email protected]”, userinterfaceonly:=True

‘we can also use the line of code below

‘ThisWorkbook.Sheets(“Sheet1″).Protect Password:=”[email protected]”, userinterfaceonly:=True

End Sub

Private Sub cmdDisplayUserForm_Click()
End Sub

Further Reading:

Worksheet.Protect method (Excel)

Advanced User-Form