VBA code to filter numbers that do not exist in a range

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
167
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone. I need a VBA code to filter numbers that do not exist in column B to column D as shown in the picture. Thank you

1692257170351.png
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try with VBA solution
Click the button "RUN" to generate the Output


VBA Code:
Option Explicit
Sub test()
Dim i&, j&, k&, rng, res()
rng = Range("B3:B14").Value
ReDim res(1 To UBound(rng), 1 To 1)
For i = 1 To UBound(rng) - 1
    For j = i + 1 To UBound(rng)
        If rng(j, 1) = rng(i, 1) + 1 Then
        Else
            k = k + 1
            res(k, 1) = rng(i, 1) + 1 & IIf(rng(i, 1) = rng(j, 1) - 2, "", " - " & rng(j, 1) - 1)
        End If
        Exit For
    Next
Next
Range("D3:D1000").ClearContents
Range("D3").Resize(k, 1).Value = res
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,674
Messages
6,126,138
Members
449,294
Latest member
Jitesh_Sharma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top