2. Learn VBA - FOR Loops
Loops are fundamental to programming, and in this tip, we'll look at FOR loops.
If you have never programmed before then this step by step guide will show you how to write your first program.
Q. What is a loop ?
A. I think this is best explained using an example.
Suppose you're at a farm, and a pig has just given birth to 10 piglets. The farmer asks you which is the biggest piglet. In order to answer this question, you will look at how big each piglet is, and once you have looked at all the piglets, you'll make your decision. A loop is the programming equivalent of looking at each piglet. Now lets use this example.
Step1: When you have the data as shown in the picture, Press ALT + F11 to bring up the VBA editor. Step2: You'll now need to insert a module, so right click on the blue area shown in the screen shot, and go: insert=>module
Step3: Now, in the white space provided, type the following code:
Step4: Click anywhere within the code, and press F5 - F5 runs code. You will now see a message
box showing which piglet is the biggest.
Download workbook to play with
VBA training Video - FOR Loops
- Nick's blog
- Login or register to post comments
- 27845 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago