Université EUROMED de Fès
Euromed Business School
                                         VBA for Excel
                                         Lab 4
                                         Loops
Exercise 1:
Write VBA code to calculate the sum of numbers from 1 to 100 using:
   1. A For loop.
   2. A While loop.
   3. A Do-While loop.
Exercise 2:
Write VBA code to find the first multiple of 7 greater than a given number in A1 using:
   1. A While loop.
   2. A Do-While loop.
Exercise 3:
Write VBA code to count the even numbers between 1 and a given number in A1 using:
   1. A For loop.
   2. A While loop.
   3. A Do-While loop.
Exercise 4:
Create a password verification system where the user must enter “12345”. Choose the best loop.
Exercise 5:
Write VBA code to calculate the factorial of a number in A1 using:
   1. A For loop.
   2. A While loop.
Exercise 6:
Write a VBA code to calculate the product of numbers from 1 to 10 using:
   1. A For loop.
   2. A While loop.
Prof. Khawla TADIST                                                                         1
Exercise 7:
Find the smallest square (e.g., 1², 2², etc.) greater than a given number in A1 using:
   1. A While loop.
   2. A Do-While loop.
Exercise 8:
Count how many numbers between 1 and a given number in A1 are divisible by 3 using:
   1. A For loop.
   2. A While loop.
Exercise 9:
Write a VBA code to repeat a message “Hello, VBA!” in column A for a given number of times
specified in A1 using the appropriate loop.
Exercise 10:
Write a VBA code to calculate the sum of all odd numbers between 1 and a given number in
A1 using:
   1. A For loop.
   2. A While loop.
Prof. Khawla TADIST                                                                        2