Udate 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

2 thoughts on “Udate Records in Excel Database with User Form

  1. Steve Fowler

    I have followed the instruction in the video. When I click on Update, the record being updated remains in its original row with none of the data having been changed. The updated record overwrites the record in the first row. The record that is originally in the first row is lost

    1. Rehan khan

      Even am facing the same issue its actually updating the row which decleard in intiliz form code currentrow =2. Thats what is updating each time when i try to update any row in the sheet


Leave a Reply

Your email address will not be published. Required fields are marked *