Help me with VBA Code

Yashraj Jadhao

New Member
Joined
Nov 14, 2021
Messages
9
Office Version
  1. 2021
Platform
  1. MacOS
Place a button labelled “Prime or Not Prime” into a spreadsheet that when pressed executes a macro
named PrimeorNot that asks the user to type in a number using the InputBox() function, it then uses
a loop structure to attempt to divide the number with integer numbers beginning with 2 and going up
by one unit at a time (e.g. it attempts to divide by 2, then 3, then 4, etc.). Your macro should check
when the user types in their number to make sure it is a number greater than zero and that it is an
integer (note, prime numbers are typically defined as numbers that are positive), and if it is not then
they should tll the user “Your number was not a positive integer. You must reselect a positive integer
to test for being prime.” and then have them input another number using the InputBox function. (Note:
A WHILE loop can be used to do this type of input, test, and repeat function very efficiently). If the
macro finds that any number divides evenly into the user’s number then have it print a message to the
user using the MsgBox() function that states “Your number is not prime”. If it finds that no number
divides evenly into the number divides then have it return a message to the user using the MsgBox()
function that states “Your number is prime.” NOTE: You can stop and report a number is not prime if
any number divides evenly into it. You also only need to test up to numbers equal to ½ the user
number (you can think about why).
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the MrExcel board!

Most of us have already done our fair share of assignments so you really cannot expect us to do yours for you. ;)
However, if you can get some of the way and get suck on some small aspects of it, you can show us what you have done and we may be able to nudge you in the right direction so you can make further progress.
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top