## Filter not shared values out of two cell ranges [UDF]

This post describes a custom function (User defined Function) that extract values existing only in one out of two cell ranges, see picture above. For example, value II is not extracted because it exists in both cell ranges Range1 and Range2.

This UDF is usefulÂ if you have lots of data and a formula is too slow.

Array formula in cell range B9:B22:

To enter an array formula, type the formula in a cell then press and hold CTRL + SHIFT simultaneously, now press Enter once. Release all keys.

The formula bar now shows the formula with a beginning and ending curly bracket telling you that you entered the formula successfully. Don't enter the curly brackets yourself.

### Excel user defined function

Function Filter_Values(rng1 As Variant, rng2 As Variant) As Variant ' This udf filter values that exists only in one out of two ranges Dim Value As Variant Dim temp() As Variant Dim Test1 As New Collection Dim Test2 As New Collection ReDim temp(0) rng1 = rng1.Value rng2 = rng2.Value On Error Resume Next For Each Value In rng1 If Len(Value) > 0 Then Test1.Add Value, CStr(Value) Next Value For Each Value In rng2 If Len(Value) > 0 Then Test2.Add Value, CStr(Value) Next Value Err = False For Each Value In Test2 If Len(Value) > 0 Then Test1.Add Value, CStr(Value) If Err Then Test1.Remove Value End If Err = False Next Value For Each Value In Test1 temp(UBound(temp)) = Value ReDim Preserve temp(UBound(temp) + 1) Next Value On Error GoTo 0 Filter_Values = Application.Transpose(temp) End Function

### How to add the User definedÂ Function to your workbook

1. Press Alt-F11 to open visual basic editor

2. Press with left mouse button on Module on the Insert menu

3. Copy and paste the above user defined function

4. Exit visual basic editor

5. Select sheet1

6. Select cell range A1:A5000

7. Type =Filter_Values(Sheet2!A1:J500, Sheet3!A1:J500) into formula bar and press CTRL+SHIFT+ENTER

The excel file contains 5000 random values in each range.

### User defined function category

This article demonstrates two ways to calculate the number of times each word appears in a given range of cells. […]

This article demonstrates how to convert a range of cells containing strings separated by a delimiter into a range of […]

This article demonstrates a User Defined Function (UDF) that counts unique distinct cell values based on a given cell color. […]

This article describes how to count unique distinct values in list.Â What is a unique distinct list?Â Merge all duplicates to one […]

Blake asks: I have a somewhat related question, if you don't mind: I have very large amount of text in […]

This article demonstrates two formulas that extract distinct values from a filtered Excel Table, one formula for Excel 365 subscribers […]

AJ Serrano asks: I have a column where each rows contains different values and I wanted to obtain the duplicate […]

This article demonstrates a user defined function that extractsÂ duplicate valuesÂ and alsoÂ count duplicates. Example, the image below shows a list containing […]

The User Defined Function demonstrated in the above picture extracts unique distinct values also considering lower and upper case letters. […]

This blog post describes how to create a list of unique distinct words from a cell range. Unique distinct words […]

This blog post describes how to create a list of unique words from a cell range. Unique words are all […]

I tried the array formula in this post: Filter common values between two ranges using array formula in excel to […]

The image above demonstrates a User Defined Function thatÂ extracts all words containing a given string that you can specify. In […]

This article describes how to find a sum from a range of numbers using a user defined function. LetÂ´s see […]

Question:I would like to reduce the number of open items by identifying positive and negative amounts that net to zero […]

In this post I will describe a basic user defined function with better search functionality than the array formula in […]

This article demonstrates formulas that count values in cell based on a delimiting character. The image above shows a formula […]

Macros and custom functions are great, they can automate many tedious tasks. To have them available whenever you need them, […]

In this vba tutorial I am going to show you how to return values from an udf, depending on where […]

This article demonstrates a user definedÂ function that lists files in a ggiven folder and subfolders. A user defined function is […]

This blog post describes how to createÂ permutations, repetition is NOT allowed. Permutations are items arranged in a given order meaning […]

This blog post demonstrates a custom function (UDF) that createsÂ permutations. Repetition is allowed. The custom function lets you specify the […]

This article explains how to perform multiple lookups based on values in one cell with a delimiting character using a […]

Sean asks: Sheet1A B C D 8 Country Europe 9 Lights 100 10 Type A 200 11 12 Country USA […]

The image above demonstrates a user-defined function in cell range B6:D7 that allows you to search a folder and subfolders […]

This article demonstrates formulas and a UDF that searches for values in a table based on concatenated values and returns […]

Question: How do I divide values equally into groups (3 lists or less)? This post shows you two different approaches, […]

The SUBSTITUTE and REPLACE functions can only handle one string, this article demonstrates two ways to handle more than one […]

This post describes two ways to a search multiple ranges and calculate a total of the corresponding values across worksheets […]

This article describes two ways to perform lookups in multiple in multiple cross reference tables simultaneously. The first one being […]

## Excel categories

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form