VBA User Forms videos | Excel VBA Forms Pt 17 - Editing Data

Posted by Andrew Gould on 18 April 2016


User forms aren't just for data entry; you can use them to edit and delete data too! This video explains how to create a form which allows the user to browse a set of records held in a worksheet and to edit and delete that data using the form. Along the way, you'll learn about a couple of advanced programming techniques such as declaring Enumerations and Property statements.

This video has the following accompanying files:

File name Type Description
Profitable Films.xlsm Excel workbook with macros

Click to download a zipped copy of the above files.

There are no exercises for this video.

Making a  video bigger

You can increase the size of your video to make it fill the screen like this:

View full screen

Play your video (the icons shown won't appear until you do), then click on the full screen icon which appears as shown at its bottom right-hand corner.

 

When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.

Improving the quality of a video

To improve the quality of a video, first click on the Settings icon:

Settings icon

Make sure you're playing your video so that the icons shown appear, then click on this gear icon at the bottom right-hand corner.

 

Choose to change the video quality:

Video quality

Click on Quality as shown to bring up the submenu.

 

The higher the number you choose, the better will be your video quality (but the slower the connection speed):

Connection speed

Don't choose the HD option unless you have a fast enough connection speed to support it!

 

Is your Wise Owl speaking too slowly (or too quickly)?  You can also use the Settings menu above to change your playback speed.

This page has 5 threads Add post
27 Aug 21 at 19:12

Hi Andrew,

Thank you so much for this amazing Userform Tutorials, I just need to ask you, from your experience, what is the recommended number of Controls shall be used in a Single Userform?

30 Aug 21 at 07:53

Hi Avdou,

I don't think that there is a definitive answer to that question. Add as many controls as you need to allow your users to provide the inputs they need. There are several ways to separate controls to reduce the number that are visible at the same time, as we've discussed in other comments.

I hope that helps!

24 Aug 21 at 17:24

Hi Andrew,

1. I have alot of controls in the user form which makes it very large and messy, can I split them into related multi page control? or multi user forms?

2. Can a mulitpage control shows or hide another multipage control? is this a recommended approach?

3. If the user is required to enter almost 22 data entry for just one record? shall I split them into related multi page control? or not to use a user form at all and use direct excel sheet in VBA?

25 Aug 21 at 07:44

Hi Avdou,

You can certainly split controls using a multi page on the form. There is a video in this series on working with multi page controls.

You can embed a multi page control within a multi page control, or show/hide a multi page control programmatically, or divide your form into separate forms, or just use a worksheet with embedded controls instead. I think that you and your users have to decide on the best approach - what makes life easiest for your users?

I hope that helps!

27 Dec 20 at 13:43

Hi Andrew ... your excel userforms videos are amazing, I have actually learned alot from you.

I just have a small question to you, I need to make a small tool that depends on entering more that 200 records ... is it effecient to let the user to enter the 200 records manually in a userform like the Film Detais Userform or is there any other mechanism.

Another thing if I will do some calculations and generating some reports as per the User Inputs ... shall I need to use userforms or just use the Excel Vba along with ActiveX Controls?

Thank you so much

28 Dec 20 at 06:33

Hi Avdou,

I think that entering 200 records manually will take a long time whichever method you choose.  I would probably not use a user form for this and rely on the user entering data directly into a worksheet. This will allow them to take advantage of copy and paste and the autocomplete feature to speed up data entry. You can use Data Validation to control what values the user enters into specific cells.

I don't think that you need user forms to create reports either - it will almost certainly be easier to provide buttons on the worksheet.

I hope that helps!

01 Oct 18 at 16:23

Andrew,

 

Many thanks for the response. On a quick first read it looks as if that is exactly what I need and looks to be simpler and more elegant than the changes I was planning to make.

I am currently sitting on a boat in Croatia so I won’t get a chance to give this a try until I am back home, but I will do so as soon as I can.  I hope that revisiting past code did not take up too much of your valuable time.

Once again many thanks,

regards,

Colin Murdoch

02 Oct 18 at 07:42

You're most welcome Colin!  It's nice to know that the videos are still being used years after they were published.  Enjoy Croatia!

26 Sep 18 at 13:27

Andrew,

Many thanks for all the excellent videos.  I have been using them to add to my knowledge of VBA. 

I have been using the downloaded file accompanying this video as a basis of a project for myself (personal) as a stock system for my model collection.  Many of my controls are combo boxes from standard lists.  The basic work very well, but I hit on the idea of adding an extra page containing duplicate combo boxes and using these as a basis to set filters.  This works OK and a simple subroutine filters the data in the main worksheet.  However your "NavigateToRecord" ignores the filters and displays all the hidden rows.

I have started building a single element array to hold the row numbers of the visible rows which works OK, and I am about to write a different sub to replace your navigation routine.  However I wondered of there was a slick way your routine could be made to ignore the hidden rows?  If so this could save a lot of work.

As this video is now 2 years old, not sure if you will pick this up but thanks in anticipation.

Regards,

Colin Murdoch.

01 Oct 18 at 10:37

Hi Colin,

If I had to do this I'd probably use a collection to hold the visible ID cells and populate this when the form is loaded.  At the top of the form's code page you could add this:

'NEW LINE
Private VisibleIDCells As Collection

'NEW SUBROUTINE
Private Sub PopulateVisibleIDCells()
    
    Set VisibleIDCells = New Collection
    Dim r As Range
    
    For Each r In wsFilms.Range("A3", _
        wsFilms.Range("A1048576").End(xlUp)).SpecialCells(xlCellTypeVisible)
        
        VisibleIDCells.Add r, r.Address

    Next r
    
End Sub

You can then make a call to the PopulateVisibleIDCells subroutine in the Initialise event of the form.

You'll also need to modify the way the RecordCount property works:

Private Property Get RecordCount() As Long
    
    'ALTERED LINE
    RecordCount = wsFilms.Range("A3", _
        wsFilms.Range("A1048576").End(xlUp)).SpecialCells(xlCellTypeVisible).Cells.Count
    
End Property

At the beginning of the ReadDetails subroutine, you'll need to change the way you set a reference to the current ID cell:

Private Sub ReadFilmDetails()
    
    'ALTERED LINE
    Set CurrentIdCell = VisibleIDCells(CurrentRecordId)

I haven't tested this rigorously (it took long enough to remind myself what I'd done in the first place!) but the basics appear to work when I apply different filters to the list of films.

I hope that points you in the right direction!