banner



How To Create A Knowledge Base In Excel

Information Technology, Networking, Security, Excel, VBA, Scripting, Automation, SEO, Cisco and CompTIA certified.

How to Create User Forms using VBA in Excel

Published Dec 22, 2016 Last updated Jan 18, 2017

What is VBA, Why Should I Intendance?

Visual Bones for Applications (VBA) is the programming linguistic communication behind Microsoft Part Products. It enables a programmer to automate these products. For example, y'all could write VBA lawmaking that enables the user to only click a button. The program could scrape several websites containing stock information. If a certain stock meets a set condition, the plan could dump that information into a nice pivot tabular array within Excel. Information technology could then send certain data to PowerPoint. The code could then take the graphs, tables, etc. that were automatically created in Excel and produce a slide deck. This slide deck could so be emailed to a ready group of users within Outlook. All this can exist completely automatic. The applications of VBA are heed-blowing, in fact, I automated my job using VBA. Given the example above y'all can see how versatile VBA can exist, particularly if you accept routine tasks, reports, and/or data that you run through any Microsoft Role product(southward).

What Practice I Demand

You simply need Microsoft Excel. A great feature about VBA is that you do not need a standalone editor, the editor is included within Excel. A fun place to commencement on your journeying to VBA proficiency is creating user forms. I chose a UserForm as an introduction to VBA considering it showcases how you can plow an otherwise boring Excel spreadsheet into a Graphical User Interface (GUI) with buttons, drop downs, and more.

What Volition I Learn?

You will learn how to create a UserForm in Microsoft Excel. A UserForm is useful for endless applications. UserForms tin can exist used to create grocery lists, address books, rosters, todo lists and a whole lot more! Creating a friendly GUI, allows even the most computer illiterate user to perform data entry tasks like an adept. Dramatically increasing efficiency; eliminating redundancy and restricting entries to only the available options. This is a recipe for success in any data entry job.

For this tutorial, I have created a UserForm that allows link builders an efficient fashion to runway websites that they accept outreached. A big office of Search Engine Optimization (SEO) involves edifice links with quality invitee posts. Keeping rails of all the websites requires a lot of organization, hence the UserForm. Of grade, experience free to tweak information technology to your needs, that is half the fun and a bang-up way to learn. This quick and like shooting fish in a barrel UserForm records the website, contact information, blazon of link, previously contributed option, and whatsoever notes the user may have. The UserForm ensures uniformity and that required fields incorporate text. In addition, it allows a seamless data entry process and eliminates the demand to navigate cells in the spreadsheet, saving time. The UserForm guides the user with the information that is wanted and limits the blazon of information entered to preset options. The UserForm also ensures the data is entered in the correct place and allows control over what format, fashion, and content are allowed, creating uniformity.

Allow's Get Started!

Open up Microsoft Excel.

Enable the Developer tab to bring up the Visual Basic for Applications Editor. Go to File (top left of Excel).

VBA in Excel

Select "Options" at the bottom.

VBA in Excel

Select Customize Ribbon in the Excel Options window.

VBA in Excel

Under Main Tabs, check the Developer box. Click OK.

VBA in Excel

The Developer tab should at present be visible in the Microsoft Excel ribbon.

VBA in Excel

To access the VBA editor, select the Developer tab and click the Visual Basic push button (acme left). Alternatively, you can access the editor by pressing ALT+F11 on your keyboard.

In the file tree window that displays your projects, select your workbook, most likely it will be labeled VBAProject (Book1). Expand the project and right click "ThisWorkbook", select Insert, and so select UserForm.

VBA in Excel

A UserForm and Toolbox will be displayed.

VBA in Excel

The Toolbox is a floating window that can be dragged wherever you lot would like. Select a control from the Toolbox and place it in the UserForm. Each control serves a different purpose. Experience free to try dissimilar controls. This tutorial covers what I consider the nigh popular controls.

Resize the UserForm as desired. In the Toolbox, select the Label Control (the capital A).

VBA in Excel

If y'all can't run across your Toolbox. You can bring it dorsum up again past clicking the Toolbox icon at the top of the VBA editor.

VBA in Excel

Once y'all accept the Label control selected, draw any labels that you want on your UserForm.

VBA in Excel

Now add a TextBox (icon that has "ab|").

VBA in Excel

Draw the TextBox on your UserForm.

VBA in Excel

At present let's add a Frame to our UserForm (the icon is a square with XYZ on top).

VBA in Excel

Draw a Frame where you would like. I like to use frames to isolate and label a control.

VBA in Excel

You can rename the Frame Explanation in the Backdrop window on the left, besides equally a myriad of other options; like fonts, images, colors, and more than – play effectually!

VBA in Excel

At present let's add some OptionButtons into the Frame.

VBA in Excel

You tin change the Explanation the same manner that you lot did for the Frames.

VBA in Excel

You tin also change the gild of the TabIndex in the Backdrop section. The TabIndex starts at 0. When a user hits the Tab primal, the focus will cycle through the TabIndex based on the social club you specify. Very useful when yous are entering data.

VBA in Excel

Now select a CheckBox and draw information technology on the UserForm. The Properties can exist adjusted the aforementioned mode as the other controls.

VBA in Excel

Depict another TextBox in the "Notes" Frame.

VBA in Excel

And then select the ScrollBar icon in the Toolbox.

VBA in Excel

Depict the ScrollBar on the right side of your new TextBox.

VBA in Excel

Next, we tin add a CommandButton. Select the square icon and depict the CommandButton in the UserForm.

VBA in Excel

Nosotros will write code that determines what the CommandButton does, as well as the other Controls.

VBA in Excel

For a bit of fun, yous can add an image to your UserForm. Click on an empty area in your UserForm and the Properties window volition appear for the UserForm. In the Motion picture section, you can import an image to appear as the groundwork.

VBA in Excel

By selecting a group of cells on your spreadsheet, you can Merge the cells to create a GUI illusion within your spreadsheet. I chose to do this and add bluish as the background color. Additionally, I created a header: Website, Contact, Type, Previously Contributed?, and Notes. I as well added a Border around those cells and made the text Bold.

VBA in Excel

At present for the code! Right-click the UserForm and select View Code, alternatively, you lot tin can striking the F7 button on your keyboard.

VBA in Excel

Re-create and paste the code below. I take made notes within the code to assist y'all sympathise what does what.

          Pick Explicit  Individual Sub CloseButton_Click()     Unload Me Cease Sub  Private Sub OKButton_Click()            'Written by joshuabriansnow@gmail.com  Dim NextRow Every bit Long  '            Make sure Sheet1 is active     Sheets("Sheet1").Actuate            '   Make sure a website is entered     If WebsiteField.Text = "" Then         MsgBox "Y'all must enter a website."         WebsiteField.SetFocus         Exit Sub     End If  '            Make sure an e-mail is entered     If EmailField.Text =            ""            Then         MsgBox            "You lot must enter a contact."            EmailField.SetFocus         Exit Sub     Terminate If            '   Determine the adjacent empty row     NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + iv          '            Transfer the website     Cells(NextRow, 1) = WebsiteField.Text            '   Create a border effectually cell     Cells(NextRow, i).Borders.LineStyle = xlContinuous      '            Transfer the email     Cells(NextRow, 2) = EmailField.Text            '   Create a border around cell     Cells(NextRow, 2).Borders.LineStyle = xlContinuous      '            Transfer the link            type            If OptionGuestPost Then Cells(NextRow, 3) =            "Guest Post"            If OptionResource Then Cells(NextRow, 3) =            "Resource"            If OptionOther Then Cells(NextRow, 3) =            "Other"            '   Create a border around jail cell     Cells(NextRow, 3).Borders.LineStyle = xlContinuous      '            Transfer previously published condition     If CheckBox1 = True Then Cells(NextRow, 4) =            "Yeah"            If CheckBox1 = False Then Cells(NextRow, 4) =            "No"            '   Create a edge effectually cell     Cells(NextRow, four).Borders.LineStyle = xlContinuous      '            Transfer notes     Cells(NextRow, 5) = NotesField.Text            '   Create a border around cell     Cells(NextRow, 5).Borders.LineStyle = xlContinuous      '            Articulate the controls            for            the next entry     WebsiteField.Text =            ""            EmailField.Text =            ""            OptionGuestPost = True     WebsiteField.SetFocus     CheckBox1 = False     NotesField.Text =            ""            End Sub                  

Y'all can identify a button on your spreadsheet, that when clicked, volition bring upward your UserForm. Select the Programmer tab in the Ribbon. Select Insert, then under the Grade Controls, add together a Button.

VBA in Excel

You can draw the Button on the spreadsheet, it volition inquire you lot to assign a Macro.

Depicts CommandButton attaching to Macro

You are all done! Be sure to Save Equally a Macro-Enabled Workbook.

VBA in Excel

Wrapping upwards

We talked about how to get the editor set within Excel. Touched base on several of the popular controls available in UserForms. We besides went over some options in the Properties carte du jour and learned how to bring it all together.

VBA is very versatile and certainly is not limited to UserForms. Think when I gave the example of scraping websites for stock information? You could take that same example a bit further. Peradventure you could build a UserForm with CheckBoxes of several different stocks. You could write some VBA lawmaking to tell Excel to take hold of the current stock quote of only the stocks that have been checked, emailing certain people if the stock rises or drops at ready points. The possibilities are endless, even on the become, you lot tin run Excel through your smart telephone.

Yous (hopefully) take made it to the terminate of this tutorial with a working instance of a UserForm! Peachy chore! Information technology is my hope that this tutorial piques your interest in VBA. You tin can actually impress in the workplace when you start automating! Perchance you can even automate your job, or portions of it, freeing up time to write articles similar this 😉

Source: https://www.codementor.io/@joshsnow/how-to-create-user-forms-using-vba-in-excel-ohexf1txo

Posted by: clarkcasits.blogspot.com

0 Response to "How To Create A Knowledge Base In Excel"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel