Yashraj Jadhao
New Member
- Joined
- Nov 14, 2021
- Messages
- 9
- Office Version
- 2021
- Platform
- MacOS
What's wrong with this code, whenever I input any number it always says not prime, I want it to tell whether its prime or not prime?
Sub Button1_Click()
Dim number As Long
Dim counter As Integer
Dim remainder As Integer
remainder = 0
remainder = Cells(3, 2)
number = Cells(2, 2)
Cells(2, 2) = InputBox("Insert positive integer")
Do While Cells(2, 2).Value < 0
MsgBox ("Your number was not a positive integer")
Cells(2, 2) = InputBox("Insert positive integer")
Loop
For counter = 1 To number / 2
Cells(3, 2) = number Mod counter
Cells(3, 2).Value = 0
Next counter
If remainder = 0 Then
MsgBox ("Your numberis not prime")
Else
MsgBox ("Your number is prime")
End If
Sub Button1_Click()
Dim number As Long
Dim counter As Integer
Dim remainder As Integer
remainder = 0
remainder = Cells(3, 2)
number = Cells(2, 2)
Cells(2, 2) = InputBox("Insert positive integer")
Do While Cells(2, 2).Value < 0
MsgBox ("Your number was not a positive integer")
Cells(2, 2) = InputBox("Insert positive integer")
Loop
For counter = 1 To number / 2
Cells(3, 2) = number Mod counter
Cells(3, 2).Value = 0
Next counter
If remainder = 0 Then
MsgBox ("Your numberis not prime")
Else
MsgBox ("Your number is prime")
End If