VBA proble to find the prime numbers between 1 and n numbers! Write a program th
ID: 3550472 • Letter: V
Question
VBA proble to find the prime numbers between 1 and n numbers!
Explanation / Answer
Sub Macro1()
'
' Macro1 Macro
'
Dim count As Integer
Dim pos As Integer
num = InputBox(Prompt:="Enter upper range of numbers", Title:="Enter number", Default:=" ")
Range("A1").Value = "Prime numbers in the range 1 to " & num
Range("A2").Value = "1"
pos = 3
For x = 1 To num
count = 0
For y = 1 To x
If ((x Mod y) = 0) Then
count = count + 1
End If
Next y
If (count = 2) Then
Range("A" & pos).Value = x
pos = pos + 1
End If
Next x
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.