How to Create a UserForm Like a Pro

Ғылым және технология

How to Create a UserForm Like a Pro
Creating UserForms in VBA should not be that complicated. However, there are lots of pitfalls for the unwary. For example
1. How do you retrieve a value after the userForm closes?
2. How do you avoid automation errors if the error cancels using X?
3. How do you stop a modeless UserForm from disappearing?
4. How do you pass the initial settings to the UserForm before the initialize event runs?
...and so on.
In this video, I show how to create a Modal and Modeless UserForm and how to avoid the issues that arise when you use them.
💻🔧 #VBA #VBAUserForm #UserForm #ExcelVBAUser #modal
Join my course
Effective Excel VBA
▸bit.ly/3wDYEnX
SUBSCRIBE TO THE CHANNEL: bit.ly/36hpTCY
DOWNLOAD THE SOURCE CODE: shorturl.at/yBSVX
Learn how to build Excel VBA Applications the right way using best practices and proven techniques
The Excel VBA Handbook Course(TheExcelVBAHandbook.com)
Free Excel VBA Resources
Excel VBA Articles (excelmacromastery.com/vba-art...)
Useful VBA Shortcut Keys
========================
Debugging:
Compile the code: Alt + D + L OR Alt + D + Enter
Run the code from the current sub: F5
Step into the code line by line: F8
Add a breakpoint to pause the code: F9(or click left margin)
Windows:
View the Immediate Window: Ctrl + G
View the Watch Window: Alt + V + H
View the Properties Window: F4
Switch between Excel and the VBA Editor: Alt + F11
View the Project Explorer Window: Ctrl + R
Writing Code:
Search keyword under cursor: Ctrl + F3
Search the word last searched for: F3
Auto complete word: Ctrl + Space
Get the definition of the item under the cursor: Shift + F2
Go to the last cursor position: Ctrl + Shift + F2
Get the current region on a worksheet: Ctrl + Shift + 8(or Ctrl + *)
To move lines of code to the right(Indent): Tab
To move lines of code to the left(Outdent): Shift + Tab
Delete a Line: Ctrl + Y(note: this clears the clipboard)

Пікірлер: 75

  • @Excelmacromastery
    @Excelmacromastery4 ай бұрын

    Let me know in the comments below, if you have struggled with UserForms. Make sure to download the source code from the link in the description below👇

  • @darinhinds960

    @darinhinds960

    3 ай бұрын

    getting a run time error (381) with this code

  • @andrewvidale
    @andrewvidale2 ай бұрын

    This is wonderful! Ive been writing VBA for decades, but, as an old school procedural programmer who grew up writing Fortran I've always known there was a much better way than global variables to pass data to and return values from forms but until now I'd not happened across it, thank you.

  • @simondechoisy779
    @simondechoisy7794 ай бұрын

    Love the fact that you demonstrate encapsulation. This is the thing I see most commonly wrong when userforms are written!

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Very true.

  • @R72Investments
    @R72Investments4 ай бұрын

    World class! But we know nothing but world class from Paul 👍

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Thanks Marcel

  • @tomharrington1453
    @tomharrington1453Ай бұрын

    Great video. I am going to have to watch this at least one more time. There is a lot of information in this video.

  • @user-mr8cy4uf3o
    @user-mr8cy4uf3o4 ай бұрын

    Using properties for user forms never crossed my mind. I used to declare global variables inside the user form instead. That was very helpful, thank you! ❤

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    You're welcome

  • @gonzaortin739

    @gonzaortin739

    4 ай бұрын

    I didnt know either. As I try to avoid global variables, I was calling subs and passing parameters. The property way is better.

  • @chrishixson487
    @chrishixson4874 ай бұрын

    The audio volume drops quite bit around 11:30. Content is great. Thank you!

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Just saw that now. Glad you enjoyed the video.

  • @SolutionsByPVV
    @SolutionsByPVV3 ай бұрын

    Oh, Paul ! This is a very useful tutorial video on how to use custom forms.

  • Ай бұрын

    Wow, I'm really impressed. Literally all the tutorials for userform don't follow your approach of good software design and follow the bad design you mentioned. I would also ask, if is possible to know about a book that teaches you good software practices for creating databased and retrieving data ?

  • @free3690
    @free36904 ай бұрын

    Another amazing video. I created a similar UserForm years ago and just reuse it with different content. Your video shows different ways the form might not work as expected, so I’m going to try and see if it will break my code! Thanks so much.

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    You're welcome

  • @johnwayne8059
    @johnwayne80594 ай бұрын

    Well done Paul, as usual!😉🤟😎

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Thanks John

  • @olivermeyer3963
    @olivermeyer39632 ай бұрын

    Hi Paul many thanks for this video and all your videos. Very cool stuff. Just in case some day you are looking for new content for Excel and VBA let me know.

  • @RogerFPrida
    @RogerFPrida4 ай бұрын

    The last advice you provided, about the late binding of the userform, is great. I struggled to figure out how to prevent the userform from hiding, and never managed to do it.

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Glad it was helpful. Not an obvious solution at all.

  • @kcerny43
    @kcerny434 ай бұрын

    Paul, thank you so much. I like a combination of user form with properties. Very impressive!

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Glad you like it

  • @billroberts2808
    @billroberts28084 ай бұрын

    Thanks Paul! I implement user forms and other objects to help direct users in performing tasks - and control activities in a logical direction. You showed how to keep from using live data in Excel - great idea! Best regards.

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Thanks Bill

  • @danielsantos2201
    @danielsantos22014 ай бұрын

    Excellent class, I learn a lot of interesting things. Thank you very much !

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    You're welcome

  • @josh_excel
    @josh_excel4 ай бұрын

    Definitely learned some things. Thanks!

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    You're welcome

  • @temyraverdana6421
    @temyraverdana64214 ай бұрын

    Great lesson. Thanks a lot

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Glad you like it

  • @godisalmighty4449
    @godisalmighty44494 ай бұрын

    Thank you so much.

  • @big1975E
    @big1975E4 ай бұрын

    This is another awesome video! Do you think it would be worth it to do a more in-depth video on properties and all the different ways they can be used other than a userform if there are any?

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    A videos on the userform controls would probably be the most likely.

  • @user-bx9ki1xk3l
    @user-bx9ki1xk3l4 ай бұрын

    Hi @Paul..Thank you for all your tutorials, I really learned a lot...could you please make a tutorial on searchable dropdown list without using a class, just a normal sub and no overriding of events. Your approach is the fastest among tutorials that I've watched. I tried it with my 27k of rows and it seems very smooth. I have comboboxes that are dependent on the search result. Thank you.

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Just at the class member subs/functions to the userform.

  • @vijaysahal4556
    @vijaysahal45564 ай бұрын

    Amazing ❤

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Thanks

  • @hammeedabdo.82
    @hammeedabdo.824 ай бұрын

    Thank you, Paul, for all the ideas and projects you provide. Please, can you give me the source from which you took the idea of creating a trading simulator?

  • @abdulrehmanmughal8235
    @abdulrehmanmughal82354 ай бұрын

    amazing informative

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Thanks. Glad you like it.

  • @ragnarok7976
    @ragnarok79764 ай бұрын

    Silly ol me typing out my properties by hand when you can actually insert them... I even googled for something like that and nothing I could find mentioned it 😮 Learn something new everyday!

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Glad you found it useful.

  • @PhongNguyen-qf5ue
    @PhongNguyen-qf5ueАй бұрын

    very good | Nguyen Hong Phuc

  • @vinothkumarmanoharan2317
    @vinothkumarmanoharan23174 ай бұрын

    My expected one.

  • @uraharakisuke1893
    @uraharakisuke18933 ай бұрын

    Great class, I'm loving your videos, thank you very much! I have a question though: I not simply evoke the userform by it's own name (e.g. myUserform.Show) instead of assigning it to a variable (Dim uf As New myUserform...) before showing/initializing it (uf.Show)?

  • @VladikHannzzeboff
    @VladikHannzzeboff4 ай бұрын

    Hi, Paul! Useful video, like all your other videos. I am interested in your opinion, tell me, please, I have noticed that in most cases for integer numbers you always use a long type instead of an integer type, even when the number is theoretically up to 30k, does the types affect the performance of macros and is it worth spending time on it or just always use a long type? Thank you in advance for your answer 😊

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Use Long "Traditionally, VBA programmers have used integers to hold small numbers, because they required less memory. In recent versions, however, VBA converts all integer values to type Long, even if they're declared as type Integer. So there's no longer a performance advantage to using Integer variables; in fact, Long variables may be slightly faster because VBA does not have to convert them." - learn.microsoft.com/en-us/previous-versions/office/developer/office2000/aa164506(v=office.10)?redirectedfrom=MSDN

  • @ravenmarks.eduardo142
    @ravenmarks.eduardo1423 ай бұрын

    Hi sir Paul. I'm a big fan of your VBA coding. I was just wondering. Is there anyway that we could possibly write code in VS code in replacement to VB code Editor?

  • @Jamesedwardkoch
    @Jamesedwardkoch4 ай бұрын

    Thank you for all your help in VBA. I wanted to ask if you have ever done a video specifically about the Gremlins in VBA, the kind of errors where all the code disappears, or where it runs one PC but not another, with little to know explanation. If you haven't yet then i would really appreciate it if you would. Because those gremlins make me less trusting of VBA, especially when you're doing it freelance. These are the kind of errors where the cause is unknown and cannot be repeated but are instead intermittent. Thanks

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    The first line of defence is making sure that office is up to date. It's difficult to do a video on them as they are elusive by nature.

  • @Jamesedwardkoch

    @Jamesedwardkoch

    4 ай бұрын

    @@Excelmacromastery thank you so much for replying. I'll do that now, update office. But maybe it's still worth talking about, maybe put a poll out 🤓

  • @hammeedabdo.82
    @hammeedabdo.824 ай бұрын

    Do you recommend using VBA to create trading robots, indicators, or even automate trading? If yes, where is the right place to start, and what is your general advice?

  • @ragnarok7976

    @ragnarok7976

    4 ай бұрын

    VBA is great for automating things in Excel but it gets pretty complex if you want to use it outside of that scope. I'd probably recommend using something like Python since it's more general purpose and in my experience, it integrates better with other languages/software than VBA does. There are probably more tutorials available for Python too... Likely even some specific to trading bots. There are also libraries (like pandas) that make it easy to read data from and save data to Excel workbooks. Hope it helps!

  • @hammeedabdo.82

    @hammeedabdo.82

    4 ай бұрын

    @@ragnarok7976thank you for your help. I hope we can see Mr. Paul's opinion on this .

  • @annathy
    @annathy2 ай бұрын

    @Excelmacromastery do you have a code that will show only the last 10 enteries in the listbox on the user form? When you have hundreds of items, it would be awesome to just show the last few. I would appreciate any help. Many thanks!

  • @gonzaortin739
    @gonzaortin7394 ай бұрын

    Wow

  • @karenbrock2379
    @karenbrock23793 ай бұрын

    Sorry I am lost at the start , used to do lots of ms access stuff years ago but I get the boxes, buttons etc but the VBA stuff is a bit to fast to follow. My F7 +Shift is not working which just makes things really slow too

  • @Dexter101x
    @Dexter101x4 ай бұрын

    Cool to know that there's a hack to get the user form back after minimising Excel

  • @TheSardOz
    @TheSardOz4 ай бұрын

    Hi Paul, I have got a question .. i have implemented few new Userforms into a quite large dashboard this forms simply paste/delete and display values, but since then the work book crashes in a odd way, looks like the VBA editor dies.... is a bit odd to me has this happens without having the forms running... Any guess from you about what it could be?

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Not easy to know without seeing rhe code.

  • @TheSardOz

    @TheSardOz

    4 ай бұрын

    happy to send you an email if you have time ... @@Excelmacromastery

  • @ragnarok7976

    @ragnarok7976

    4 ай бұрын

    Do you have any lists or combo boxes on those forms that reference a table (list object) on a sheet? I have crashed excel before using rowsource with a table reference and then trying to manipulate the data. Hope you figure it out either way!

  • @TheSardOz

    @TheSardOz

    4 ай бұрын

    hey mate thanks for sharing.... no non od the data the form read or write is a table object , but i do use RowSource to load data into a listbox@@ragnarok7976

  • @Mk-lp9tm

    @Mk-lp9tm

    4 ай бұрын

    It happened to me lately while building my workbook. Apparently, copying and pasting repeatedly uses a lot of memory and will eventually lead into crashes. Application.CutCopyMode = false did the trick for me.

  • @SAMSITARAGUYANG
    @SAMSITARAGUYANG3 ай бұрын

    What your link documentation vba sir...

  • @edgarsantarosa9847
    @edgarsantarosa98474 ай бұрын

    Hello Paul 👋🏻, I have a class that apply masks to texbox. Can I send it to you if want to make video about to the others. I see it's a struggling in Excel VBA, regards Edgar

  • @Excelmacromastery

    @Excelmacromastery

    4 ай бұрын

    Send it on and I'll take a look.

  • @edgarsantarosa9847

    @edgarsantarosa9847

    4 ай бұрын

    @@Excelmacromastery sure! I just need translate the code, because I'm from Brazil, then I'll send it to you

  • @prediction2302
    @prediction23023 ай бұрын

    How userform password protected that anyone not able to break password

  • @byteseq
    @byteseq4 ай бұрын

    From 15:48 to 16:00 you repeatedly say "Worksheet" when you mean "UserForm"...

Келесі