How to Extract 4-Digit Numbers Preceded by a Pound Symbol in Excel

Abstract: Extracts four-digit numbers immediately following a pound symbol in Excel using TEXTAFTER and LEFT or FIND and MID functions.

Created: 2026-09-19 by

You can extract 4-digit numbers preceded by a pound symbol in Excel using either the legacy Find and Mid functions or the modern TEXTAFTER and LEFT combination. These methods locate the specific character sequence and isolate the numeric portion without requiring external plugins or complex array formulas.

Understanding the Data Structure

Before applying any formula, it is crucial to understand how Excel handles text strings containing mixed characters. The pound symbol (often referred to as the hash character) acts as a delimiter that marks the start of your target data. In many business datasets, such as product codes, reference IDs, or temporary access keys, this pattern appears consistently, for example, as #1234 or #5678. Excel does not have a native regular expression function like REGEX.EXTRACT, which is a common misconception. Instead, you must rely on string manipulation functions that search for specific substrings. The goal is to find the position of the # symbol, skip over it, and then capture exactly four characters following it. This approach works regardless of whether the surrounding text varies in length, provided the format remains consistent. For more advanced text handling, you might also want to explore how to manage long text strings effectively. See our guide on Find & Replace 15+ Character Text in Excel: Preventing It from Turning into Scientific Notation to ensure your extracted data retains its formatting integrity.

Method 1: Using TEXTAFTER and LEFT Functions

This method is available in Excel 365 and Excel 2021 onwards. It is the most readable and robust approach for modern users. The logic involves two steps: first, extracting everything after the pound symbol, and second, taking only the first four characters of that result. Assume your data is in cell A2 and looks like Ref:#1234 End. You can use the following formula:
=LEFT(TEXTAFTER(A2, "#"), 4)
The TEXTAFTER function searches for the delimiter "#" and returns all text that follows it. If the cell contains multiple hashes, TEXTAFTER defaults to the last occurrence unless specified otherwise. By wrapping this in the LEFT function with an argument of 4, you strictly limit the output to the four digits immediately following the symbol. If there is a space between the hash and the numbers, such as # 1234, you should adjust the delimiter to include the space: "# ". This ensures the extraction starts directly at the digit. If the cell does not contain a hash, TEXTAFTER will return the original text, so it is wise to wrap the formula in an IFERROR function to handle missing data gracefully:
=IFERROR(LEFT(TEXTAFTER(A2, "#"), 4), "Not Found")

Method 2: Using FIND and MID Functions

For users on older versions of Excel or those who prefer traditional string parsing, the combination of FIND and MID provides a reliable alternative. This method calculates the exact starting position of the text to extract. The formula structure is:
=MID(A2, FIND("#", A2) + 1, 4)
Here is how the logic breaks down: 1. FIND("#", A2) locates the numerical position of the first pound symbol in the string. For example, in Ref:#1234, the hash is at position 5. 2. Adding + 1 shifts the starting point to the character immediately following the hash. In our example, the extraction begins at position 6. 3. MID takes the text from A2, starts at the calculated position, and extracts 4 characters. Like the previous method, this assumes the data is well-formed. If the hash is missing, FIND will throw a #VALUE! error. To prevent this, nest the formula within an IF(ISNUMBER(FIND(...))) check:
=IF(ISNUMBER(FIND("#", A2)), MID(A2, FIND("#", A2) + 1, 4), "")
This conditional statement checks if the hash exists before attempting to extract. If it does not exist, the formula returns an empty string instead of an error code, keeping your spreadsheet clean.

Handling Edge Cases and Variations

Real-world data is rarely perfect. You may encounter scenarios where the number of digits varies, or where the pound symbol is used differently. For instance, if some cells contain #12345 (five digits) and others contain #1234, the fixed-length extraction of 4 will truncate longer codes or leave shorter ones incomplete if they don't exist. In such cases, consider using Power Query for bulk processing. Power Query allows you to split columns by delimiter and select specific parts of the resulting list, offering a visual interface for complex text splitting rules. This is particularly useful when dealing with thousands of rows where formula performance might become a bottleneck. Additionally, if your data includes dynamic dates or other changing values, ensure that your extraction logic does not interfere with date formatting. As noted in our analysis of Dynamically Changing Dates in Excel Formulas Using Cells, mixing text extraction with date arithmetic requires careful type checking to avoid unintended conversions.

Verifying Your Results

After applying either formula, always verify a sample of the results. Check for leading zeros; Excel often drops leading zeros from numeric-looking strings. If preserving 0123 is important, format the destination column as Text before entering the formula, or wrap the result in TEXT(..., "0000") to force a four-digit display. Finally, test edge cases such as empty cells, cells with only the hash symbol, and cells with no hash symbol. Ensuring your formula handles these gracefully prevents downstream errors in reports or dashboards that rely on this extracted data.

Frequently Asked Questions

What if the pound symbol is followed by a space?

You must include the space in your delimiter string. Use "# " inside the TEXTAFTER or FIND function to ensure the extraction starts at the first digit rather than the space character.

How do I keep leading zeros in the extracted number?

Format the destination cells as Text before applying the formula. Alternatively, wrap your extraction formula in TEXT(result, "0000") to force Excel to display exactly four digits, including any leading zeros.

Why does my formula return an error for some rows?

This usually happens because the row lacks the pound symbol. Wrap your formula in IFERROR or check for the existence of the symbol using ISNUMBER(FIND()) to return a blank value or custom message instead of an error.

Can I extract numbers if there are multiple hash symbols in one cell?

By default, TEXTAFTER finds the last occurrence, while FIND finds the first. Specify the occurrence index in TEXTAFTER(text, delimiter, occurrence_num) to target a specific hash symbol in the string.

Is there a way to extract variable-length numbers after the hash?

The current methods extract a fixed length. To extract until a specific end delimiter, you would need nested LEFT and SEARCH functions or use Power Query to split by multiple delimiters dynamically.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More