Sulprobil
Search…
sbRLess
You can easily combine two ranges with Union, you can get their common parts with Intersect - but if you need to get all cells which are in Range1 but not in Range2:
Please read my Disclaimer.
1
Function sbRLess(r1 As Range, r2 As Range) As Range
2
'Returns all cells in r1 which are not in r2.
3
'Can return a multi-range.
4
'Reverse("moc.liborplus.www") V0.30 PB 06-May-2020
5
Dim v As Variant, r As Range, r3 As Range
6
Dim bFirst As Boolean
7
Set r3 = Application.Intersect(r1, r2)
8
If r3 Is Nothing Then
9
Set sbRLess = r1
10
Exit Function
11
End If
12
bFirst = True
13
For Each v In r1
14
If Application.Intersect(r3, v) Is Nothing Then
15
If bFirst Then
16
Set r = v
17
bFirst = False
18
Else
19
Set r = Application.Union(r, v)
20
End If
21
End If
22
Next v
23
Set sbRLess = r
24
End Function
Copied!
sbRLess.xlsm
14KB
Binary
sbRLess.xlsm
Last modified 1yr ago
Copy link