IMSEC Function in Excel

Sumit Bansal
Written by

Sumit Bansal is the founder of TrumpExcel.com and a 13-time Microsoft Excel MVP. He started this site in 2013 to share his passion for Excel through easy tutorials, tips, and training videos, helping you master Excel, boost productivity, and maybe even enjoy spreadsheets!

The IMSEC function in Excel returns the secant of a complex number. The secant is 1 divided by the cosine, so IMSEC does for complex numbers what the SEC function does for regular angles.

You’ll mostly need it in math and engineering worksheets, where a number has a real part and an imaginary part. Excel has no number type for these, so IMSEC reads a complex number written as text (like “0.5+0.5i”) and gives its answer as text too.

Two things can trip you up. IMSEC won’t take a range directly, so pointing it at a whole column returns one #VALUE! error, and a blank cell quietly returns 1 instead of an error.

In this article, I’ll show you how to use IMSEC with five examples, including a one-formula version for a whole column and a fix for those blank-cell 1s.

Follow along with the example file

IMSEC Function Examples.xlsx

Download

IMSEC Function Syntax

Here is the syntax of the IMSEC function:

=IMSEC(inumber)
  • inumber – The complex number you want the secant of.

The argument takes a complex number written as text, or a cell that holds one. When you type a complex number straight into the formula, put it in double quotes, so =IMSEC("0.5+0.5i") returns 0.949978867615495+0.239827630938088i.

The letter at the end marks the imaginary part. You can use i or j, and IMSEC keeps whichever letter you used in its result, but the letter has to be lowercase.

You can also give it a plain number. IMSEC treats it as a complex number with no imaginary part, so =IMSEC(1) returns 1.85081571768093.

The IMSEC function works in Excel 2013 and later versions, including Excel for Microsoft 365, Excel 2024, 2021, 2019, 2016, and Excel for Mac.

When to Use the IMSEC Function

Use this function when you need to:

  • Find the secant of complex numbers in a math or engineering worksheet
  • Check your answers for complex trigonometry homework
  • Work with complex numbers written in j notation, the way electrical engineers write them
  • Get the secant of a whole column of complex numbers with one formula

Let me show you a few practical examples of how to use the IMSEC function.

Example 1: Find the Secant of a Complex Number in Excel

Let’s start with a simple example.

Below is a list of complex numbers labeled z1 to z10, and I want to find the secant of each one in column C.

List of complex numbers labeled z1 to z10 with an empty Secant column

Here is the formula to enter in cell C2 and copy down:

=IMSEC(B2)
IMSEC formula in C2 copied down returns the secant of each complex number

IMSEC takes the complex number in B2 and returns its secant. So for 1.5+0.5i, you get 0.288435422115541+1.87959176434572i.

The result is text in the same x+yi form, with up to 15 significant digits in each part. When a part of the result is 0, Excel leaves it out.

That’s why z5 (1.2i) returns 0.552286154278205 with no i at the end. A number with only an imaginary part always has a secant with no imaginary part.

z7 holds the plain number 0.75, which is why it sits on the right side of its cell while the complex numbers sit on the left. IMSEC treats it as 0.75 with no imaginary part and returns 1.36670112467223.

Now look at z1 and z8. The number -1.5-0.5i is 1.5+0.5i with both signs flipped, and both return exactly the same secant, because the secant of a number and the secant of its negative are always equal.

Since the secant is 1 divided by the cosine, you could also get it with IMDIV(1,IMCOS(B2)). Here, the IMCOS function gets the cosine of the complex number, and the IMDIV function divides 1 by it.

IMSEC does the same job in one step, and the two results can differ only in the 15th digit.

I’ve kept this first example as a per-row formula so you can see IMSEC work on one number at a time. The next example handles the whole column with one formula.

Example 2: Get the Secant of a Whole Column with One Formula

In Excel 365 (and Excel 2021 or later), you can get the secant of a whole column with a single formula, but IMSEC needs one small trick to do it.

Below is a list of signal values written in j notation, and I want to get the secant of each one in column C.

Signal values in j notation with an empty Secant column and an empty Result cell in F2

The obvious formula would be to give IMSEC the whole range. I’ve put that attempt in cell F2, and it returns a #VALUE! error:

=IMSEC(B2:B11)
IMSEC with a plain range in F2 returns the #VALUE! error

This happens because IMSEC can’t take a multi-cell range reference like B2:B11. It only works with single values, or with a list of values held in memory (called an array).

Putting a plus sign (+) in front of the range fixes this, because Excel then hands IMSEC the values as an array. Here is the formula that works:

=IMSEC(+B2:B11)
IMSEC with a plus sign before the range in C2 spills the secant of every value

Enter this in cell C2, and it spills the results down to C11. IMSEC also keeps the j in its results, so 0.6+1.1j returns 0.558626152552174+0.30593208494682j.

Important: Use just the plus sign here. A double minus (--) also turns the range into an array, but it tries to convert the text to numbers first, so every complex number returns #VALUE!.

The same plus-sign trick works for other functions that won’t spill when you give them a range.

If you are using Excel 2019 or earlier, enter the below formula in cell C2 and then copy it down the range:

=IMSEC(B2)

Example 3: Use Separate Real and Imaginary Part Columns

Sometimes your complex numbers aren’t written as text at all. The real part sits in one column and the imaginary part in another.

Below is a table with the real part of each complex number in column A and the imaginary part in column B, and I want to get the secant of each complex number in column C.

Real and imaginary parts in separate columns with empty secant columns

Here is the formula to enter in cell C2:

=IMSEC(COMPLEX(+A2:A11,+B2:B11))
IMSEC with COMPLEX in C2 spills the secant built from the two part columns

The COMPLEX function joins each pair of parts into one complex number, so 1.3 and 0.6 become 1.3+0.6i. IMSEC then returns its secant, and the results spill down to C11.

Both ranges need the plus sign because COMPLEX has the same range limitation as IMSEC. COMPLEX then hands its results to IMSEC as an array, so IMSEC doesn’t need a plus sign of its own.

The results in column C are text, so you can’t round them or plot them in a chart directly. To get the real and imaginary parts of each secant as regular numbers, enter this formula in cell D2:

=HSTACK(ROUND(IMREAL(+C2#),4),ROUND(IMAGINARY(+C2#),4))
HSTACK formula in D2 splits each secant into rounded real and imaginary numbers

How this formula works:

  • The IMREAL and IMAGINARY functions pull the real and imaginary parts out of each secant as numbers.
  • +C2# refers to the whole spilled result in column C. IMREAL and IMAGINARY have the same range limitation as IMSEC, so C2# needs the plus sign before they can use it.
  • ROUND(…,4) rounds each part to four decimal places.
  • The HSTACK function puts the two results side by side, so one formula fills both columns D and E.

So the secant in row 2, 0.664964543985102+1.28637893744704i, becomes 0.6650 in column D and 1.2864 in column E.

Row 9 (0 and 2.1) has a real part of 0, so its secant (0.241294506201855) has no imaginary part, and column E shows 0.0000. Row 10 (2.8 and 0) has an imaginary part of 0, so its secant has no imaginary part either.

HSTACK is available only in Excel 365 and Excel 2024, so here’s how to do the same thing in older versions.

If you are using Excel 2019 or earlier, start with the secant itself. Enter the below formula in cell C2 and then copy it down the range:

=IMSEC(COMPLEX(A2,B2))

Then, in any version without HSTACK (including Excel 2021, where the column C formula above still spills), enter the below formula in cell D2 and copy it down the range:

=ROUND(IMREAL(C2),4)

And enter this formula in cell E2 and copy it down the range:

=ROUND(IMAGINARY(C2),4)

Example 4: Stop Blank Cells from Returning 1 in IMSEC

When complex numbers are typed in by hand, blank cells and a few small slips can give you results that look fine but aren’t.

Below is a list of typed complex numbers with some uppercase I and J slips, two blank cells, and one genuine 0, and I want to get the secant of each one in column C.

Typed complex numbers with uppercase I and J, two blank cells and a 0

Here is the formula to enter in cell C2:

=IMSEC(+B2:B11)
IMSEC on the typed values in C2 returns #NUM! for uppercase letters and 1 for blank cells

Three rows return #NUM!, and three more return 1. The #NUM! errors are easy to spot, but the 1s are the sneaky ones, because they look like real answers.

IMSEC reads a blank cell as 0, and the secant of 0 is 1 (the cosine of 0 is 1). So entries 3 and 7, which are empty, show 1 as if they held a number.

Entry 5 is a real 0, so its 1 is the correct answer. You just can’t tell it apart from the blank rows by looking at column C.

The #NUM! errors come from the uppercase letters. IMSEC only recognizes a lowercase i or j, so 0.5-1.4I, 2.1+0.3J, and 0.3+2.2I aren’t read as complex numbers at all.

Here is a formula that fixes the letter case and leaves blank rows empty. Enter it in cell D2:

=IF(B2:B11="","",IMSEC(LOWER(B2:B11)))
IF and LOWER formula in D2 fixes the uppercase letters and leaves blank rows empty

The LOWER function changes I and J to i and j, so those three entries now work. LOWER returns an array, so the range doesn’t need a plus sign here.

The IF function checks for blank cells and returns an empty string for them, so entries 3 and 7 now stay empty. Entry 5 still shows 1, which is the correct secant of 0.

I’ve used IF instead of the IFERROR function on purpose. With IFERROR(IMSEC(LOWER(B2:B11)),""), the blank rows would also come out empty, because LOWER turns a blank cell into empty text, which IMSEC rejects with #NUM!.

But IFERROR would also hide an entry that’s genuinely wrong (like 2+i3), so you’d never know it needs fixing.

If you are using Excel 2019 or earlier, enter the below formula in cell D2 and then copy it down the range:

=IF(B2="","",IMSEC(LOWER(B2)))

Example 5: IMSEC vs SEC for Regular Angles

Since IMSEC accepts plain numbers, you can use it on regular angles too. But Excel has the SEC function for that, and this example shows why it’s the better choice.

Below is a list of angles in degrees, and I want to get the secant of each angle with IMSEC in column B and with SEC in column C.

Angles in degrees with empty IMSEC Result and SEC Result columns

Here is the IMSEC formula to enter in cell B2:

=IMSEC(RADIANS(A2:A11))
IMSEC with RADIANS in B2 returns the secant of each angle as text

The RADIANS function converts each angle from degrees to radians, which is what IMSEC expects. RADIANS returns an array, so IMSEC spills without a plus sign.

Most of the values are right (60 degrees gives 2, and 180 degrees gives -1). I’ll come back to the giant numbers at 90 and 270 degrees in a moment.

The bigger issue is that they’re all text, which is why they sit on the left side of the cells. Because they’re text, number formatting won’t apply to them, and the SUM function skips them.

Here is the SEC formula to enter in cell C2:

=SEC(RADIANS(A2:A11))
SEC with RADIANS in C2 returns the secant of each angle as numbers

SEC returns real numbers, so you can format them, round them, and total them like any other numbers.

At 90 and 270 degrees, the secant doesn’t exist, because the cosine of those angles is 0. But neither function shows an error.

At 90 degrees, IMSEC shows 16324552277619100, and SEC shows the same huge number as 1.63246E+16.

That’s because RADIANS turns 90 degrees into pi divided by 2, and Excel can’t store pi exactly. So the cosine comes out as a tiny number very close to 0 instead of exactly 0.

When you see a giant result like this, read it as “the secant doesn’t exist here.”

So for regular angles, use SEC. Keep IMSEC for numbers that have an imaginary part.

If you are using Excel 2019 or earlier, enter the below formula in cell B2 and then copy it down the range:

=IMSEC(RADIANS(A2))

And for the SEC column, enter the below formula in cell C2 and then copy it down the range:

=SEC(RADIANS(A2))

So these are some practical ways to use the IMSEC function in Excel to get the secant of complex numbers.

Just remember to put a plus sign in front of a range when you want one formula for a whole column, and keep an eye out for blank cells quietly returning 1. I hope you found this article helpful.

List of All Excel Functions

Other Excel Articles You May Also Like:

Sumit Bansal

Sumit Bansal

13x Microsoft Excel MVP

Hey! I'm Sumit Bansal, founder of trumpexcel.com and a Microsoft Excel MVP. I started this site in 2013 because I genuinely love Microsoft Excel (yes, really!) and wanted to share that passion through easy Excel tutorials, tips, and Excel training videos. My goal is straightforward: help you master Excel skills so you can work smarter, boost productivity, and maybe even enjoy spreadsheets along the way!

Get the FREE 51 Excel Tips Ebook

Enter your details and the free PDF is on its way to your inbox.

Hmm, that didn't go through. Please check your email and try again.

No spam. You'll also get my weekly Excel newsletter. Unsubscribe anytime.

Check your inbox!

The ebook is on its way to your email. It usually lands within a couple of minutes.