BalbasNiBarabas
New Member
- Joined
- Jun 1, 2020
- Messages
- 5
- Office Version
- 2019
- Platform
- 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.
So this is my activity:
Create a VBA function called Test 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:
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.
Thanks!!!!
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.
So this is my activity:
Create a VBA function called Test 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:
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!!!!