How to Program in Visual Basic in Excel

Next Video:
How to Delete Blocked Cookies....5

To program using Visual Basic in Microsoft Excel, open the Visual Basic editor by holding the "Alt" key and pressing "F11," and then create a custom code to run in an Excel spreadsheet. Create and assign a macro in order to run the function in an Excel program with instructions from a software developer in this free video on Microsoft Excel.

Part of the Video Series: Computer & Internet Tips
Promoted By Zergnet


Video Transcript

Hi, my name's Dave Andrews. Today I'm going to show you how to program in Visual Basic in Excel. Let's open up Microsoft Excel. We're going to click on our Start button. Go to All Programs. Let's find Microsoft Office and just launch Excel. Now, once Excel is finally opened up we're going to open up the Visual Basic editor. And the way we do this is by holding down the Alt key and we're just going to press F11 which brings up the Visual Basic editor within Excel. This allows us to create a custom code that will actually run in our Excel spreadsheets. I'm going to write a function by going to Insert. I'm going to choose Module. And as you can see here, I have a new Visual Basic Module. So I'm going to put a function in here called Run Me. That's basically what it's going to do is just be a function that we run and I'm going to begin writing a simple program here. So now that my little program is completed, as you can see here, I've created several integers here, row and column and value. I've created another object that's pointing to our current worksheet. And the way that I did that was I set it to the active workbook, sheets, and then sheet 1. Now, here I have a loop which loops from 1 to 5 both on the row value and the col value, multiples them together and stores that in value. And then within the current cell that I'm in, row and column, I say 'the value row times the value column equals' and then the result of those two multiplying together. So basically, I'm just going to do a little multiplication table. So let's close out of our Visual Basic editor and we have to have a way to make that code work. So I'm going to Insert and I'm just going to put a little shape on here that kind of looks like a button. Just like that. And I'm going to assign a macro to this button by right-clicking on it and saying Assign Macro. And we're going to create a new macro and all that macro's going to do is say module1.runme which is the name of our function. Now, if I close out of Visual Basic editor, click on my little button, here, as you can see, it's just filled in my multiplication table. One times one equals one, one times two equals two and so on here. So we can see that five times three equals fifteen and such and such. My name's Dave Andrews and I've just showed you how to program Visual Basic in Microsoft Excel.


Related Searches

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!