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

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

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

  1. 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. 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 *