LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default One range inside another, Intersect

After I had the same situation, and reading some posts about checking to see
if the cells in one range were contained in another range, I wrote the
function below.

It returns the boolean True or False value, and optionally, if range A is
not entirely within range B, the first failing cell is returned.

Public Function bRngAinRngBF(RngA As Range, RngB As Range, _
Optional FailedRng As Range = Nothing) As Boolean
'True if every cell in RngA is in RngB. 1 Area is OK in either.
'When False, the 1st cell in RngA not found in RngB is returned in FailedRng.

Dim CellA As Range
Dim IxB As Integer, IxA As Integer


Set FailedRng = Nothing
If RngA Is Nothing Or RngB Is Nothing Then Exit Function

For IxA = 1 To RngA.Areas.Count
For Each CellA In RngA.Areas(IxA)

For IxB = 1 To RngB.Areas.Count
If Not Intersect(CellA, RngB.Areas(IxB)) Is Nothing Then Exit For
'found
Next IxB

If IxB RngB.Areas.Count Then
Set FailedRng = CellA
Exit Function
End If

Next CellA
Next IxA

bRngAinRngBF = True ' Both loops complete, function is true

End Function


--
Neal Z
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
intersect named range in different workbook Jason[_9_] Excel Discussion (Misc queries) 2 October 17th 07 09:43 PM
Faster way to find what part of a range (actually addresses) not intersect with another one? tskogstrom Excel Programming 1 June 17th 07 08:38 AM
Combine Intersect Range in If statements Ben Dummar Excel Discussion (Misc queries) 5 March 22nd 07 10:37 PM
Calendar range and date intersect [email protected] Excel Programming 2 August 27th 06 07:21 PM
Intersect check range DoctorG Excel Programming 2 March 17th 06 07:33 PM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"