Excel formulas for common tasks
Each page starts with the formula that does the job, then shows it working on a live sheet you can edit, explains why it works step by step, and gives the variants you'll need next. Every formula is calculated before the page is published, and each page says where Excel and Google Sheets differ.
- Get the last value in a column
=XLOOKUP(TRUE,F2:F13<>"",F2:F13,,0,-1)Return the last filled cell of a column in Excel or Google Sheets, even with blank cells in between: XLOOKUP from the bottom, or INDEX with COUNTA.
- Rank without skipping numbers after a tie (dense rank)
=SUMPRODUCT((E$2:E$11>E2)/COUNTIF(E$2:E$11,E$2:E$11))+1RANK.EQ skips a number after a tie (1, 1, 3). A dense rank gives 1, 1, 2. The formula with SUMPRODUCT and COUNTIF, for Excel and Google Sheets.
- Calculate hours worked minus lunch (and night shifts)
=MOD(D2-C2,1)*24-E2/60Hours worked from start and end times, minus a break in minutes, as a decimal for payroll. Works for shifts past midnight. For Excel and Google Sheets.
- Extract text between two characters in Excel (substring)
=MID(B2,FIND(" ",B2)+1,FIND(" ",B2,FIND(" ",B2)+1)-FIND(" ",B2)-1)Get the substring between two characters in Excel (two spaces, hyphens or brackets) with MID and FIND, or TEXTBEFORE and TEXTAFTER. Live example included.
- Count unique values with a condition
=COUNTA(UNIQUE(FILTER(D2:D13,E2:E13=I1)))Count how many different values meet a condition: COUNTA, UNIQUE and FILTER in Excel 2021 and later, or SUMPRODUCT with COUNTIFS in any version.
- Compare two columns in Excel for matches and differences
=IF(COUNTIF($G$2:$G$8,B2)>0,"Yes","No")Compare two columns in Excel for matches: row by row with =, or in different rows with COUNTIF, then filter for the differences. Live sheets, Excel and Sheets.
- Budget vs actual: variance and variance %
=D2-C2Variance is actual minus budget, variance % is actual ÷ budget − 1, and a flag shows what's over. The three formulas on a live budget, Excel and Sheets.
- How to count cells with text in Excel
=COUNTIF(E2:E7,"*")The Excel formula to count cells with text is =COUNTIF(range,"*"): it counts text and skips numbers and blanks. COUNTA counts every non-empty cell.
Have a formula you can't read? Paste it into the formula explainer. Looking for one function's syntax? See the function reference.