Function Primo(N As Integer) As Boolean Dim divisor As Integer divisor = 2 Do While ((divisor <= N) And (N Mod divisor <> 0)) divisor = divisor + 1 Loop Primo = (divisor = N) End Function Function ProxPrimo(N As Integer) As Integer Dim Candidato As Integer Candidato = N + 1 Do While (Not (Primo(Candidato))) Candidato = Candidato + 1 Loop ProxPrimo = Candidato End Function Sub NPrimos() Dim Quant As Integer Dim I As Integer Dim Inicial As Integer Quant = Cells(1, 1) I = 1 Inicial = 1 Do While (I <= Quant) Cells(I, 2) = ProxPrimo(Inicial) Inicial = Cells(I, 2) I = I + 1 Loop End Sub