VBA Function from Flowchart to Code

BalbasNiBarabas

New Member
Joined
Jun 1, 2020
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hi guys!


I am a new learner to VBA. I am the type of learner that I would like to know the logic and reason behind of stuff. So i have this activity that I find a bit challenging cause I can't fully understand yet the For...Next element flow chart element. I would like to know the logical reason for the sequence of the image below.

1591385342394.png


So this is my activity:
Create a VBA function called Test(n) that outputs TRUE if n is a prime number and FALSE if n is not a prime number. The flowchart that follows depicts the algorithm for determining if n is prime or not.

Flowchart:
1591385476326.png


Here's my attempt where I get soooo confused as I write my code.
TAKE NOTE: I AM NOT ASKING FOR THE CODE, BUT A BETTER WAY FOR ME TO UNDERSTAND THE LOGIC OF THE ELEMENTS INSIDE MY CODE.
VBA Code:
Function prime(n As Integer) As Integer
Dim l As Integer, i As Integer
n = ActiveCell
l = RoundDown((n, 0))
For i = 1 To n
    If i > l Then Exit Function
    For
Next i
    If n Mod i = 0 Then Flag = True

Thanks!!!!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,214,874
Messages
6,122,034
Members
449,061
Latest member
TheRealJoaquin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top