问题描述
我想确定rngA是否处于像rngB这样的闭合范围内。
I would like to determine if rngA is in a closed range like rngB.
函数UNION和INTERSECT不会起作用。
The functions UNION and INTERSECT won't do the trick.
推荐答案
Sub InnerRange()
Dim rngA As Range
Dim rngB As Range
Dim rngArea As Range
Dim lngMinRowA As Long
Dim lngMinColA As Long
Dim lngMaxRowA As Long
Dim lngMaxColA As Long
Dim lngMinRowB As Long
Dim lngMinColB As Long
Dim lngMaxRowB As Long
Dim lngMaxColB As Long
Dim blnAinB As Boolean
设置rngA =范围("H6")
lngMinRowA = Rows.Count + 1
lngMinColA = Columns.Count + 1
lngMaxRowA = 0
lngMaxColA = 0
对于每个rngArea在rngA.Areas
lngMinRowA = Application.Min(lngMinRowA,rngArea.Row)
lngMinColA = Application.Min(lngMinColA,rngArea.Column)
lngMaxRowA = Application.Max(lngMaxRowA,rngArea.Row + rngArea.Rows.Count - 1)
lngMaxColA = Application.Max(lngMaxColA,rngArea.Column + rngArea.Columns.Count - 1)
下一个rngArea
设置rngB =范围("E8:J8,J5:J7,E4:J4,E5:E7")
lngMinRowB = Rows.Count + 1
lngMinColB = Columns.Count + 1
lngMaxRowB = 0
lngMaxColB = 0
对于每个rngArea在rngB.Areas
lngMinRowB = Application.Min(lngMinRowB,rngArea.Row)
lngMinColB = Application.Min(lngMinColB,rngArea.Column)
lngMaxRowB = Application.Max(lngMaxRowB,rngArea.Row + rngArea.Rows.Count - 1)
lngMaxColB = Application.Max(lngMaxColB,rngArea.Column + rngArea.Columns.Count - 1)
下一个rngArea
blnAinB = lngMinRowA> lngMinRowB和lngMinColA> lngMinColB和_
lngMaxRowA< lngMaxRowB和lngMaxColA< lngMaxColB
MsgBox blnAinB
End Sub
Sub InnerRange()
Dim rngA As Range
Dim rngB As Range
Dim rngArea As Range
Dim lngMinRowA As Long
Dim lngMinColA As Long
Dim lngMaxRowA As Long
Dim lngMaxColA As Long
Dim lngMinRowB As Long
Dim lngMinColB As Long
Dim lngMaxRowB As Long
Dim lngMaxColB As Long
Dim blnAinB As Boolean
Set rngA = Range("H6")
lngMinRowA = Rows.Count + 1
lngMinColA = Columns.Count + 1
lngMaxRowA = 0
lngMaxColA = 0
For Each rngArea In rngA.Areas
lngMinRowA = Application.Min(lngMinRowA, rngArea.Row)
lngMinColA = Application.Min(lngMinColA, rngArea.Column)
lngMaxRowA = Application.Max(lngMaxRowA, rngArea.Row + rngArea.Rows.Count - 1)
lngMaxColA = Application.Max(lngMaxColA, rngArea.Column + rngArea.Columns.Count - 1)
Next rngArea
Set rngB = Range("E8:J8,J5:J7,E4:J4,E5:E7")
lngMinRowB = Rows.Count + 1
lngMinColB = Columns.Count + 1
lngMaxRowB = 0
lngMaxColB = 0
For Each rngArea In rngB.Areas
lngMinRowB = Application.Min(lngMinRowB, rngArea.Row)
lngMinColB = Application.Min(lngMinColB, rngArea.Column)
lngMaxRowB = Application.Max(lngMaxRowB, rngArea.Row + rngArea.Rows.Count - 1)
lngMaxColB = Application.Max(lngMaxColB, rngArea.Column + rngArea.Columns.Count - 1)
Next rngArea
blnAinB = lngMinRowA > lngMinRowB And lngMinColA > lngMinColB And _
lngMaxRowA < lngMaxRowB And lngMaxColA < lngMaxColB
MsgBox blnAinB
End Sub
这篇关于确定范围是否在闭合范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!