You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多单元格数据检测与内容返回Excel公式技术咨询

Pull the First Non-Empty Value from Specific Cells in Excel

Hey there! Great question—totally get wanting a clean, no-fuss way to grab the first (or only) non-empty value from a set of scattered cells instead of writing a messy stack of IFs. Here are a few straightforward solutions depending on your Excel version:

Solution 1: TEXTJOIN (Excel 2019, 365, or Online)

This is probably the closest to your pseudo-formula =If(J2,M2,R2,X2, print value) in terms of simplicity. The TEXTJOIN function automatically ignores empty cells, so if you pass it your target cells with an empty separator, it’ll spit out the only non-empty value (or concatenate multiple ones if there are more):

=TEXTJOIN("", TRUE, J2, M2, R2, X2)
  • Breakdown:
    • "": Empty separator (so no extra characters between values if there are multiple non-empty cells)
    • TRUE: Tells Excel to skip blank cells
    • J2, M2, R2, X2: The cells you want to check

In your example where only M2 has "Cake", this formula will return exactly "Cake". If you later have multiple non-empty cells and want to separate them (e.g., with a comma), just swap the first argument to ", ".

Solution 2: XLOOKUP (Excel 365 or 2021+)

If you want to explicitly target the first non-empty cell (and avoid concatenating multiple values if they exist), XLOOKUP is perfect. It lets you search for the first TRUE in an array of "is this cell non-empty?" checks:

=XLOOKUP(TRUE, NOT(ISBLANK({J2, M2, R2, X2})), {J2, M2, R2, X2})
  • Breakdown:
    • NOT(ISBLANK({J2, M2, R2, X2})): Creates an array like {FALSE, TRUE, FALSE, FALSE} for your example, marking which cells have content
    • XLOOKUP finds the first TRUE in that array and returns the corresponding value from your target cells

Solution 3: Nested IFs (Older Excel Versions <2019)

If you’re stuck on an older Excel version that doesn’t have TEXTJOIN or XLOOKUP, nested IFs are the way to go. It’s a bit more verbose but still logical:

=IF(J2<>"", J2, IF(M2<>"", M2, IF(R2<>"", R2, X2)))

This checks each cell in order (J2 → M2 → R2 → X2) and returns the first one that isn’t empty. If all are empty, it’ll return a blank.

All these methods work exactly as you described—no fancy loops needed, just built-in Excel functions that handle the "check each cell" logic for you!

内容的提问来源于stack exchange,提问作者PatientBelt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 19:12:42