Open In App

How to Generate All Prime Numbers Between Two Given Numbers in Excel?

Last Updated: 01 Dec, 2022

S

Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

A number greater than 1 with no positive divisors besides 1 and the number itself is referred to as a prime number. In this article, we will be discussing two approaches for generating all prime numbers between two given numbers in excel. In the first approach, we are creating formulas for generating prime numbers between two numbers, and in the second approach, we are creating a new user-defined function that is simple and easy in comparison to the first approach.

Approach 1: Using Formulas

The Define Name function and formulas can be used to list or generate every prime number between two certain values.

Step 1: Follow, the below steps for creating the first range name

  1. Click on the Formulas tab
  2. Click on Name Manager
  3. Once we click on Name Manager, a new pop-up will be opened. Now, Click New Button.
Name Manager

 

Step 2: In the New Name popup window, Enter “range” as the range name in the “Name” text field. Now, Enter this formula: 

=ROW(INDIRECT(Sheet1!$B$1&”:”&Sheet1!$B$2))

Sheet1 is the name of the worksheet we are now using, and B1 and B2 are the start and finish numbers we selected in the Refers to the text box.

INDIRECT Function

 

Press the “OK” button and close the pop window.

Step 3: Now, Again click New Button for creating another range name. Enter “prime” as a name in Name Field in the New Name pop window. Enter this below formula in refers to the field.

=SMALL(IF(MMULT(–(IF(range>TRANSPOSE(range-Sheet1!$B$1+2),MOD(range,(range>TRANSPOSE(range-Sheet1!$B$1+2))*TRANSPOSE(range-Sheet1!$B$1+2)))=0), range-Sheet1!$B$1+2)=0,range),ROW(INDIRECT(“1:”&Sheet1!$B$2)))

range variable is created in step 2.

prime

 

Click the “OK” button and close the pop window.  

Step 4: Now, Write any two numbers or ranges (B1 and B2 Column) in which range we want to print or list prime numbers as start and end numbers. We need to select any column in which we want to list or print prime numbers and we need to enter this formula in the formula bar:

=IFERROR(prime,””)

prime is a function that is created in step 3. Once we entered the formula in the formula bar and then press CTRL + SHIFT + ENTER keys together, all prime numbers will be listed in the selected column between the mentioned range.

IFERROR

 

Approach 2: Using User-Defined Functions

The first method is a little bit difficult, so, in this approach, we will apply a user-defined function for generating a prime number between two numbers. 

Step 1: Click the ALT + F11 keys together for opening the Microsoft Visual Basic for Applications window.

Insert in VBA

 

Step 2: First, Click on Insert Button and then click the Module button. 

Module in VBA

 

Step 3: Once we clicked on the Module button, a new dialog box will open. Just copy and paste this below code to open the dialog box. 

Function PRIME(Start_val, End_val As Long)

‘Updateby Extendoffice 20160613

Dim val As String

For i = Start_val To End_val

   For j = 2 To i – 1

       If i Mod j = 0 Then GoTo 20:

   Next j

   val = val & i & “,”

20:

Next i

PRIME = val

End Function

Screenshot:

prime numbers between a range

 

Step 4: Press CTRL + S to save this file and the dialog box will be closed, go back to our worksheet. Now, Select any cell and enter this below formula with two numbers as parameters such as =prime(10, 50) where 10 is starting number and 50 is the ending number. Press ENTER Key and prime numbers will be displayed to our selected cell.

prime numbers

 



S

News
Improve
Discuss
Do you want to advertise with us?Click here to know more

A

How to Generate Unique Random Numbers in Excel?

article_img
Excel is powerful data visualization and analysis program we use to create reports or data summaries. So, sometimes happen that we have to create a report and assign a random id or number in a spreadsheet then we can create a random number without any repeat and manually. Approach 1: Using =RAND() formula Now, we have to generate a random number in column A, we will select a cell and type our formula =RAND() and then press enter Drag the number till row you want the random number. After that in the second column convert all the random numbers into values using =RANK.EQ(select random number column) After that press enters and drag till random number. Congratulations! You have created unique random numbers. Approach 2:Using Kutools to create random numbers in excel.Download and install Kutools for excel in your system from here. Open excel and go to the Kutools tab and select the Insert data option.After that enter the from and to limit for creating a random number.Hurrah!! Your number will be printed in the spreadsheet.
Read More

Editing Excel Macros in Excel

article_img
Excel Macro is a set of actions that can be recorded, saved, used multiple times. This feature saves us a lot of time when dealing with repetitive tasks and huge data sets. We can always make changes to an existing Macro in Excel. There are two ways to record and run macros: Excel Commands Excel Visual Basic for Applications(VBA).1. Copying a Macro Code We can reuse the existing macro code while creating new Macros. For example, if you have existing macros created using the record function, we can reuse the code to write new macros. To open the code follow the below steps: Select Tools --> Macros --> Visual Basic Editor. Copy code from the existing macros(use Command + C) and paste(use Command + V) in the new macro2. Renaming a Macro Follow the below steps to rename a Macro in Excel: Select Tools --> Macros --> Visual Basic Editor. Select name on the left plane.Edit the name.3. Deleting a Macro Follow the below steps to delete a macro in Excel: Select Tools --> Macros --> Macros... Select the macro to be deleted. Click on the minus(-) symbol at the bottom.Select yes to delete the macro.
Read More

Best Microsoft Excel High-Paying Jobs with Excel Skills in 2024

article_img
Are you ready to unlock a world of opportunities with Microsoft Excel? In today’s data-driven job market, mastering Excel is essential for launching a successful career, whether you're a fresher or an experienced professional. In this article, we will cover the high-paying Excel jobs available in 2024, including crucial roles like data analyst, business analyst, and many more. We'll explore the qualifications needed for these positions, along with salary estimations to help you understand your earning potential. Whether you’re looking for Excel jobs for freshers or seasoned professionals, we’ll also dive into options for Excel freelancing jobs and work-from-home jobs in Excel. Equip yourself with the knowledge to excel in your career and take the first step toward a lucrative future!Best Microsoft Excel High-Paying Jobs with Excel Skills in 2024Table of ContentWhy choose a career in ExcelWhy Excel Skills Are Essential for Your CareerEssential Excel Skills Required to Boost Your Resume Best Microsoft Excel High-Paying JobsFinancial AnalystsData AnalystAdministrative Assistant Accountants Project ManagersManagement ConsultantRetail Store ManagersBusiness Analyst Market Research A
Read More

Excel VLOOKUP Function - Excel Guide for Beginners

article_img
How to do Vlookup in Excel - Quick StepsPrepare Your DataEnter the VLOOKUP Formula >>Press EnterUse a Cell Reference for Flexibility Copy the Formula for Multiple RowsThe VLOOKUP function is one of the most widely used tools in Excel for looking up and retrieving data from a table. Whether you’re working with a single sheet or multiple workbooks, VLOOKUP allows you to search for a value in one column and return a related value from another. If you're new to Excel or still getting the hang of formulas, this guide is for you. We will cover everything from the basics of how VLOOKUP works to practical examples that show how to search data across sheets, troubleshoot common issues, and master the VLOOKUP formula for any task.Excel VLOOKUP FunctionWhat is the VLOOKUP Function in ExcelThe term VLOOKUP stands for Vertical Lookup. It is designed to search for a specific value in the first column of a table (lookup column) and retrieve corresponding data from a different column in the same row.Syntax of VLOOKUP FormulaVLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])Arguments:1. lookup_value: The value you want to search for (e.g., a specific ID, name, or product code).
Read More

AI in Excel: Top 20 Excel AI Tools in 2025 (Free/Paid)

article_img
The integration of AI in Excel is transforming the way professionals manage, analyze, and visualize data. Whether you're handling large datasets, performing financial analysis, or automating repetitive tasks, AI-powered tools can significantly improve efficiency and accuracy. In 2025, advanced Excel AI tools are making complex tasks easier by offering features like data cleaning, predictive analytics, smart automation, and AI-driven insights.In this guide, we’ve gathered a list of the top 20 Excel AI tools for 2025 that are reshaping how users interact with Excel.Table of ContentBest AI Tool in Excel: Top Picks for 2025Top 10 Free Excel AI Tools in 2025Top 10 Excel AI ToolsAI in Excel: OverviewIn Excel, an AI tool (Artificial Intelligence tool) refers to an add-in or extension that leverages artificial intelligence to enhance your spreadsheet experience. These tools can automate tasks, improve data analysis, and generally make you more productive.Excel has always been a powerful tool for data analysis, but with the integration of AI tools, it has transformed into a smarter, more intuitive platform.Best AI Tool in Excel: Top Picks for 2025Explore the below AI tools designed for auto
Read More

How to Check if the Number is Prime Number in Excel?

article_img
A prime number is a number that is greater than 1 and has no positive divisor other than 1 and the number itself. Approach: To check whether the number is prime or not we have to divide the number with all the numbers between 2 and the square root of that number. And if it gives remainder 0 in any of the divisions it means that the number is a positive factor and ultimately results in a non-prime number. So if any of the divisions don't result in the remainder 0 then it means that the number doesn't have any positive factor and ultimately results in the Prime number. Take the numberIf the number is 2 then it is a Prime number else follow the next stepsDerive the square root of the numberTake the upper bound of the square root obtained and then minus it by oneDivide the number with all the numbers between 2 and the square root of the numberIf the remainder is 0 in any of the divisions then non-prime.Else it is the prime number Formula: =IF(F6=2,"Prime",IF(AND(MOD(F6,ROW(OFFSET($C$2,,,ROUNDUP(SQRT(F6),0)-1)))<>0),"Prime","Not Prime")) Let's see each of these functions one by one so that it is clearly understood. Step1: First of all check if the given number is 2 or not and if i
Read More

How to Enter Large Numbers/Credit Card Numbers into Microsoft Excel?

article_img
By default, in the cells of an Excel sheet, we canter 11 digits maximum. Once we enter a 12-digit number Excel changes it in terms of exponent and power notation. 11 digit number Now, if we enter a 12 digit number let's see what happens. We can observe that the representation of the 12-digit number becomes in terms of the power of 10 by converting to a decimal form. This is not a good representation since we can't get the accurate precision of the number from the above representation. In real life many times we deal with numbers having more than 11 digits. A great example is our Credit Card number which consists of 16 digits. So, we need an alternate way in Excel to store our Credit Card number with all the digits visible instead of decimal representation. In this article, we are going to see how to enter large numbers in Excel using a credit card number having 16 digits as an example. Example: Consider the dataset having the name, credit card number, expiry date of a geek. Insert the data in the worksheet as shown below : We can observe as we enter the 16-digit number in the worksheet Excel automatically converts it into a decimal form. So, to avoid it an alternate technique is t
Read More

Excel Chart with Two Trendlines

article_img
A line that bounds a particular chart and shows the behavior as it propagates is known as a trend line. It is generally used for analytics purposes to get a close approximate idea from the chart. The chart can be of any type like Bar Chart, Scattered Chart, Line Chart, etc. In this article, we are going to see how to add two trendlines in a chart using Excel. For this, we will consider a suitable example shown below. Example: Consider a scenario of a country having a population of more than 50 crores. People in this country are suffering from a pandemic and the number of positive cases due to a deadly virus is increasing day by day. Finally, after six months vaccines were made and the government started a vaccine jab for the people after a lot of trials. The government ordered the officials to keep a record of data for the first ten days of the vaccine jab. The record should contain two columns : The first column consists of the number of vaccines jab to the people.The number of positive cases. The moto behind is to check by mass jabbing of vaccines how the number of positive cases are changing during the first ten days. The experts from health centers made the following analysis
Read More

How to Find the Percentage of Two Cells in Microsoft Excel?

article_img
If you want to find the percentage of two cells in Microsoft Excel, Simply select an empty cell, where you want to display the percentage of the two cells. Type in the following formula in the selected cell : =address of cell1/address of cell2 For example, I want to print out the percentage of C2 and C3, so the formulae will be: =C2/C3, in an empty cell C4. As soon as you click on the return key, You will get your percentage calculated in cell C4. However, if a decimal value is displayed in the cell. Like 0.10, Simply press the shortcut key Ctrl+Shift+% to format as a percent or convert the numeric value into the percentage style and press the Return key. The Decimal value will be converted to a percentage. BeforeAfter You can also go to the Number section under the Home tab and press the % Symbol to convert to percentage format. % symbol under the Number listbox
Read More

How to Find the Intersection of Two Curves in Excel?

article_img
The intersection of the two curves is the point where the two curves meet, and their coordinates are the same. In this article, we will learn about how to find the intersection point of the two curves in excel. Finding the intersection point of two curves can be very useful in data analysis. Let's learn the steps for the same, Intersection Point of two curves in Excel Consider two sales curves of different regions Vs the year, and if they intersect at some point, then we would have insight at what time interval the sales of two different regions are matching or how close or how apart they are. For example, "Arushi" is a data analyst, and she notices that sales pattern 1 follows the curvey = x2 and sales pattern 2 follows the curvey = 2.7x. Her task is to find the intersection point of the two sales curves. Given a data set with x, y1, and y2 values, the formula used to calculate y1 values is by sales pattern 1, and the formula used to calculate y2 values is by sales pattern 2. A chart is also created. Following are the steps, Step 1: Create a new table range with headings x, y1, y2, and differences. Write any random value of x in cell D14. For example, 4. Step 2: Write the same for
Read More
three90RightbarBannerImg