eHow launches Android app: Get the best of eHow on the go.
Summary: Create a For Next Loop in Excel VBA by typing in code that runs a series of operations as soon as it is activated in the worksheet. Set WS values and operate Excel efficiently by opening up the visual basic editor with tips from a software developer in this free video on general computer tips.
Dave Andrews is a software developer with a business and Web site selling programs and other computer services in Franklin, Tenn. Having worked in the IT industry for more than 8...read more
"Hi my name is Dave Andrews and today I am going to show you how to create a for next loop Excel VBA. Let's begin by opening up Excel and click on my start button and I am just going to launch Excel. Now once you have Excel open let's open up the Excel VBA by holding down the All key on the keyboard, pressing F 11. This opens up your visual basic editor for Excel. I am going to make it to where I can see a little better and we are going to double click on sheet one. What we are going to do is we are going to put some code in here that runs when sheet one is activated so next to general click the little drop down and select worksheet and let's say activate. We are going to type some code in here. Here is our finish code. As you can see the very first thing I did is create two variables, row as an integer as callx I didn't use so I can undelete that, only one variable, row. The next variable I created was WS and that is going to be an object of type worksheet now what I did was I sent the WS value equal to the active value which is the current workbook that you are working in and I pulled out sheet one out of the sheets array for that workbook. Now we did our four next loop right here and the way you do it is you say four row which is an integer equals one to five and basically what that is going to do is count from one to five and assign those values to your row variable as it goes along. So the first time row will be one and the next time row will be two and the row will be three, four, and five and on. Now inside of this loop we say set the worksheets cell row equal to the current row that it is looping through column one. So that means in the first column rows one to five we are going to set their values to be hello. This next row ends the four next loop and tells it to loop back to the beginning so if we would minimize our VBA and then click on sheet two and then click on sheet one to activate it which remember that is where the function we put our code into was you can see that in the first column, numbers one through five are filled in with our text hello. That's how you create a four next loop in Excel. My name is Dave Andrews and I just showed you how to create a four next loop using Excel VBA."
eHow Article: How to Create a For Next Loop in Excel VBA