Using Excel and Visual BasicSolutionFunction DetermineIfPrim
Using Excel and Visual Basic
Solution
Function DetermineIfPrime(n As Integer)
If (n = 2) Or (n = 3) Then
DetermineIfPrime = True
Exit Function
End If
If ((n Mod 2) = 0) Or (n Mod 3) = 0 Then
DetermineIfPrime = False
Exit Function
End If
Dim i As Integer
i = 5
Dim w As Integer
w = 2
While (i * i <= n)
If n Mod i = 0 Then
DetermineIfPrime = False
Exit Function
End If
i = i + w
w = 6 - w
Wend
DetermineIfPrime = True
Exit Function
End Function
Sub Main()
MsgBox (\"Main Executed\")
Dim selectedRange As Range
Set selectedRange = Selection
For Each cell1 In selectedRange.Cells
If (DetermineIfPrime(cell1.Value)) Then
\'Red color
cell1.Interior.ColorIndex = 3
cell1.Font.Bold = True
End If
Next cell1
End Sub
