How to Hash Data in Excel
Ever found yourself looking at a spreadsheet full of sensitive customer data, needing to create a unique ID for each row without just using an email address? Hashing is your answer. It’s a powerful but straightforward technique to turn any piece of text - like an email or name - into a unique, anonymous fingerprint. This article will show you exactly how to hash data in Excel, giving you a valuable skill for data anonymization, comparison, and analysis.
What Exactly Is Hashing (and Why Is It Useful in Excel)?
In simple terms, hashing is the process of using an algorithm to convert an input (like an email address, name, or any text string) into a fixed-size string of characters. This output is called a "hash." Think of it as a digital fingerprint for your data.
A good hashing algorithm has three key properties:
- It's a one-way street: You can easily generate a hash from your text, but you can't reverse the process to get the original text back from the hash. This is perfect for anonymizing data.
- It's consistent: The exact same input will always produce the exact same hash. "john.smith@email.com" will hash to the same value every single time.
- It's unique: Even a tiny change to the input - like changing a single letter or adding a space - will produce a completely different hash. "John.smith@email.com" (with a capital "J") will have a totally different hash than the lowercase version.
So, why would you do this in a spreadsheet? Here are a few common business scenarios:
- 1. Anonymizing Personally Identifiable Information (PII): Imagine you need to share a sales report with an outside consultant or another department, but you can’t share the customer emails. By hashing the email column, you can provide a unique identifier for each customer without exposing their actual email address.
- 2. Creating a Unique ID: Sometimes you have a dataset without a unique identifier for each row. You can concatenate a few columns (like First Name, Last Name, and Date) and hash the result to create a reliable unique ID for every single record.
- 3. Comparing Lists Without Exposing Data: Let's say you and a partner company want to see how many customers you have in common. Neither of you wants to share your raw customer lists. If you both agree on a specific hashing algorithm (like SHA-256), you can each hash your email lists and then compare the resulting hash values to find matches without ever sharing a single email address.
- 4. Tracking Changes: You can create a hash for an entire row of data. Later, you can recalculate the hash. If it's different, you know one of the values in that row has been changed, acting as a simple data integrity check.
Excel's Missing Piece: The HASH() Function
The first thing to know is that Excel does not have a native, built-in function like =HASH(). While it's a feature many users would love, it's just not available out of the box. But don't worry, there are a couple of powerful workarounds to get the job done. We’ll cover the most reliable options: one method using Power Query and another, more flexible method using a tiny bit of code called VBA.
Option 1: Hashing with Power Query (No Code Required)
If you're already familiar with Power Query (also known as "Get & Transform Data" in newer versions of Excel), you'll be happy to know it includes built-in hashing capabilities. This is an excellent option if you don't want to touch any code and you're already using Power Query to clean and shape your data.
We'll use the SHA-256 algorithm, a widely used and secure hashing standard.
Here’s how to do it step-by-step:
Step 1: Get Your Data into Power Query
First, make sure your data is in a formatted Excel Table. If it isn't, just click anywhere inside your data range and press Ctrl + T. With your data in a table, go to the Data tab on the Ribbon and click From Table/Range. This will open the Power Query Editor.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Step 2: Add a Custom Column
With your data loaded in the Power Query Editor, go to the Add Column tab at the top and click on Custom Column.
Step 3: Enter the Hashing Formula
A new window will pop up. This is where you'll tell Power Query how to create your new hashed column.
- Give your new column a name, for example, "HashedEmail".
- In the formula box, you will use Power Query's built-in cryptographic functions. Type the following formula, replacing
[YourColumnName]with the actual name of the column you want to hash (e.g.,[Email]). Make sure to select it from the available columns list on the right to avoid typos.
Text.FromBinary(Crypto.Hash(CryptoAlgorithm.Sha256, [Email]))This formula tells Power Query to take the value from the "Email" column, apply the SHA-256 hashing algorithm to it, and then convert the result back into readable text.
Step 4: Close and Load
Click OK. You'll now see your new column filled with unique SHA-256 hashes. In the Home tab of the Power Query Editor, click the top half of the Close & Load button. Your original Excel sheet will now have a new table containing the original data plus your shiny new hashed column.
Option 2: Hashing with VBA (The Most Powerful and Flexible Method)
While Power Query is great, it can be rigid. Creating a custom VBA function is the most common and flexible way to add hashing powers directly into your workbook's formulas. You’ll be able to use it just like any other Excel function, like =SHA256(A2).
It sounds intimidating, but it’s really just a matter of copying and pasting some pre-written code once. Here we go.
Step 1: Open the VBA Editor
First, you need to bring up the Visual Basic for Applications (VBA) editor. The quickest way is to press Alt + F11 on your keyboard. Your Excel window will disappear, and you’ll see the white VBA Editor window.
Step 2: Insert a New Module
This is just a blank space to paste our code. In the VBA Editor's menu, go to Insert > Module. A blank white code window will appear in the main part of the editor.
Step 3: Paste the Hashing Code
Now, copy the code below and paste it directly into the blank module window you just opened. This code creates functions for several common hashing algorithms, including MD5, SHA1, SHA256, and SHA512.
'------------------------------------------------------------
' Universal Hashing Functions for Excel VBA
' Provides MD5, SHA1, SHA256, and SHA512
'------------------------------------------------------------
Option Explicit
Private Function HashString(ByVal sIn As String, ByVal sHashAlgorithm As String) As String
'Function to perform the hashing
Dim oT As Object ' For UTF8 Encoding
Dim oH As Object ' For Hash Algorithm
Dim b() As Byte ' For Byte Array
Dim sOut As String ' For Final Output String
'Convert the input string to a UTF-8 encoded byte array
Set oT = CreateObject("System.Text.UTF8Encoding")
b = oT.GetBytes_4(sIn)
'Create the specified hashing algorithm object
Set oH = CreateObject("System.Security.Cryptography." & sHashAlgorithm)
b = oH.ComputeHash_2((b))
'Convert the hashed byte array back to a hexadecimal string
sOut = LCase(EncodeHex(b))
HashString = sOut
Set oT = Nothing
Set oH = Nothing
End Function
Private Function EncodeHex(ByRef arrBytes() As Byte) As String
'Helper function to convert byte array to hex string
Dim objXML As Object
Dim objNode As Object
Set objXML = CreateObject("MSXML2.DOMDocument")
Set objNode = objXML.createElement("b64")
objNode.DataType = "bin.hex"
objNode.nodeTypedValue = arrBytes
EncodeHex = objNode.text
Set objNode = Nothing
Set objXML = Nothing
End Function
Public Function MD5(sIn As String) As String
MD5 = HashString(sIn, "MD5CryptoServiceProvider")
End Function
Public Function SHA1(sIn As String) As String
SHA1 = HashString(sIn, "SHA1Managed")
End Function
Public Function SHA256(sIn As String) As String
SHA256 = HashString(sIn, "SHA256Managed")
End Function
Public Function SHA512(sIn As String) As String
SHA512 = HashString(sIn, "SHA512Managed")
End FunctionStep 4: Use Your New Function!
That's it! Close the VBA Editor (click the X or press Alt + Q) to return to your regular Excel sheet. Now you have a new set of custom functions available.
In any empty cell, you can now type a formula like:
=SHA256(A2)Replace 'A2' with the cell containing the data you want to hash. When you press Enter, you'll see the SHA-256 hash. You can now click and drag the fill handle (the little square in the bottom-right corner of the cell) to apply this formula to an entire column, just like you would with VLOOKUP or SUM.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Important Tips for Clean and Consistent Hashing
Remember how we said even a tiny change creates a different hash? This is where people often get tripped up. Here are two pro tips to ensure your hashes are consistent.
1. Normalize Case with LOWER()
The hashes for "jane.doe@email.com" and "Jane.Doe@email.com" are completely different. If you want these to be treated as a match, always convert the text to lowercase before hashing it. This is called normalization.
Formula: =SHA256(LOWER(A2))
2. Remove Extra Spaces with TRIM()
A trailing space at the end of an email that you can't even see will change its hash. The TRIM() function removes any leading or trailing spaces from a text string.
Formula: =SHA256(TRIM(LOWER(A2)))
Combining TRIM() and LOWER() is a best practice that solves 99% of consistency issues when hashing raw data in a column and gives you clean, reliable results every time.
Final Thoughts
Learning how to hash data in Excel is a valuable skill that elevates your data handling capabilities. It enables you to anonymize sensitive information, create robust unique identifiers, and securely compare datasets - whether you prefer the code-free approach of Power Query or the on-the-fly flexibility of a custom VBA function, you're now equipped to manage your data with greater security and sophistication.
While mastering tasks like this directly in Excel is powerful, it's often one step in a much larger manual reporting process. We understand the hours spent exporting CSVs from various platforms, cleaning them up, and piecing them together just to get a clear picture of performance. We built Graphed to eliminate that friction entirely. By connecting directly to your tools like Google Analytics, Shopify, and Salesforce, we put all your data in one place, ready for analysis. You can ask for a complex dashboard in plain English and get it in seconds, skipping the manual spreadsheet steps for good.
Related Articles
Facebook Ads for Nail Salons: The Complete 2026 Strategy Guide
Learn how to create profitable Facebook ads for your nail salon in 2026. This comprehensive guide covers ad formats, targeting strategies, budgeting, and optimization techniques.
Facebook Ads for Locksmiths: The Complete 2026 Strategy Guide
Learn how to use Facebook ads for locksmiths in 2026 to generate quality leads beyond emergency services. Complete strategy guide covering audience targeting, creative best practices, campaign structure, and budget recommendations.
Facebook Ads for Tutors: The Complete 2026 Strategy Guide
Learn how to run effective Facebook ads for tutors in 2026. Complete guide covering targeting, ad formats, budgets, and proven strategies that convert.