Update Records in Excel Database with User Form

How to update records in an Excel database with a user-form. When we create a database and make data entries, we are bound to make mistakes. Once we discover the errors or somebody points out to them, we need to take corrective action and update the records.

Watch the video below to see how we can update records in Excel with a user-form:

This video is also available on YouTube.

Here’s the VBA code:

Dim currentrow As Long ‘declaration of the global variable right at the top

Private Sub UserForm_Initialize()
currentrow = 2
TextBox1 = Cells(currentrow, 1)
TextBox2 = Cells(currentrow, 2)
TextBox3 = Cells(currentrow, 3)

End Sub

Private Sub cmdUpdate_Click()
answer = MsgBox(“Are you sure you want to update the record?”, vbYesNo + vbQuestion, “Update Record”)
If answer = vbYes Then
Cells(currentrow, 1) = TextBox1.Text
Cells(currentrow, 2) = TextBox2.Text
Cells(currentrow, 3) = TextBox3.Value
End If

End Sub

Further reading:

Create and manage Database in Excel