The short answer: Excel has no function called SUN, because the function is spelled SUM. If you typed =SUN(A1:A10) and got #NAME?, that error means Excel does not recognise the name, and the fix is usually a one-letter correction to =SUM(A1:A10). If you actually meant something else, like a running total, a date calculation, or a solar or daylight figure you are calculating yourself, this guide covers the practical ways to build it. Menu labels can vary slightly by Excel version, device and region.
What You'll Need
- Excel on Windows, Mac, the web, or the mobile app (formulas are the same, but typing long ranges is easier on desktop or web)
- A spreadsheet with your numbers in a column or row, ideally with a header row and no blank cells inside the range
- Basic understanding of cell references such as A1 and ranges such as A1:A10
- If you are calculating sun-related values such as sunrise, sunset or daylight hours, you also need the latitude and longitude of the location and the date you are working with
Step-by-Step
- Confirm what you actually need. Most "sun in excel" searches are a typo for SUM. If you want to add numbers, use SUM. If you want a running total, use SUM with a growing range or the Subtotals feature. If you want daylight or solar angles, you build the formula yourself from inputs, because Excel ships with no built-in sun function.
- Enter your numbers cleanly. Put them in one column with a header (for example A1 = Amount, A2:A20 = values). Leave no blank rows inside the range and make sure no number is stored as text, which usually shows as left-aligned with a small green triangle in the corner.
- Type the correct formula. Click the cell where the total should appear and type
=SUM(A2:A20). Press Enter. Excel adds every number in that range and ignores blanks and text. - Add separate ranges if needed. Use a comma between ranges:
=SUM(A2:A20,C2:C20)adds both blocks. You can also mix ranges and single cells, as in=SUM(A2:A20,D5). - Use SUM with conditions. To add only rows that meet a rule, use SUMIF or SUMIFS. For example
=SUMIF(B2:B20,"North",A2:A20)adds amounts where the region column says North. SUMIFS takes multiple ranges and criteria pairs in the same pattern. - Check the result against a quick manual total. Select the same range and look at the status bar at the bottom of the window; Excel shows Sum, Average and Count there without changing the sheet. If the status bar total and your formula differ, a cell is probably stored as text or a row is outside the range.
- Copy the formula correctly. If you fill the formula down or across, use absolute references ($A$2:$A$20) when the summed range must stay fixed. Press F4 after clicking a reference to cycle between relative and absolute forms. On Mac, use Cmd+T or the F4 key depending on your keyboard settings.
- For a running total, put
=SUM($B$2:B2)in the first data row and fill down. The first reference is locked and the second grows with each row, so each cell shows the total so far. - For sun-related calculations you build yourself, start with the inputs: date, latitude and longitude. Excel's date and time values are serial numbers, so subtracting a sunrise time from a sunset time and formatting the result as a duration (use a custom format like [h]:mm) gives daylight hours. Keep the times as real time values, not text.
- Name important ranges. Select the range, type a name in the Name Box to the left of the formula bar, and press Enter. You can then write
=SUM(Amounts), which is easier to read and harder to break.
Common Mistakes
- Typing SUN instead of SUM, which returns #NAME?. Excel does not check spelling of function names, so nothing warns you until the error appears.
- Including the header row in the range when the header is text. That is harmless with SUM, but it breaks counting formulas and confuses SUMIF criteria.
- Numbers stored as text. A total of zero when the column clearly has values almost always means this. Convert with Text to Columns or by multiplying the range by 1 in a helper cell, then pasting values back.
- Using a space instead of a comma to separate ranges, or a colon where a comma is required. Both cause formula errors.
- Forgetting that hidden rows are still included by SUM. If you filtered the list, SUM adds everything in the range, not just visible rows. Use SUBTOTAL(109, range) for visible rows only.
- Expecting SUM to catch circular references. If your total cell sits inside the range it sums, Excel shows a circular reference warning and the value will be wrong.
Tips
- Use AutoSum as a shortcut: select the cell below your column and press Alt+= on Windows, or use the AutoSum button on the Home tab.
- Press Ctrl+` to show all formulas on the sheet at once, which makes it easy to spot a mislabelled range.
- Use the Evaluate Formula tool under the Formulas tab to step through a long formula and see which part returns the unexpected value.
- Keep input cells in one block and totals in another. It makes auditing easier and prevents circular references.
- For sun-related data, store latitude and longitude as plain decimal numbers and dates as real dates, then build calculations from those cells rather than hard-coding values into formulas.
Troubleshooting
If you see #NAME?, check the function spelling first, then confirm you have not used curly quotes or a non-English function name. If you see #VALUE!, a cell in the range contains text that a paired function cannot handle; SUM ignores text, but SUMPRODUCT and some array formulas do not. If the total is zero, look for text-formatted numbers and check the status bar against the range. If the total seems too high, check for duplicate rows and hidden rows inside the range. If a filled formula returns different results down the column when you expected the same range, your references shifted; add dollar signs. If Excel shows a circular reference warning, trace the arrows with the Error Checking menu or check your range boundaries.
If an update or a new version changes where a button sits, the formula bar and function names remain the same, so you can always type formulas directly.
Frequently Asked Questions
Is there a SUN function in Excel?
No. There is no built-in SUN function. The function people usually mean is SUM, and if you need solar or daylight values you build the calculation from your own inputs.
Why does Excel show #NAME? when I type SUN?
#NAME? means Excel does not recognise the function or range name. It is nearly always a spelling issue, so change SUN to SUM and press Enter.
How do I sum only visible rows after filtering?
Use SUBTOTAL with function number 109, for example =SUBTOTAL(109,A2:A20). Plain SUM adds hidden and filtered-out rows too.
Can I add numbers that meet a condition?
Yes. Use SUMIF for one condition and SUMIFS for several, keeping each criteria range the same size as the sum range.
How do I calculate daylight hours from sunrise and sunset?
Enter sunrise and sunset as real time values, subtract the earlier from the later, and format the result as [h]:mm. If the sunset appears earlier, add 1 to it to handle the overnight rollover.
Why is my SUM result a date instead of a number?
The cell is formatted as a date. Right-click the cell, choose Format Cells, and set it to General or Number.