我正在創建一個函數,用於檢查Range2中是否包含單元格(Range1)。該功能是:檢查範圍是否包含在另一個函數
Function IsWithin(Range1 as Range, Range2 as Range) as Boolean
這意味着在Before_DoubleClick
事件去檢查單擊單元格屬於範圍。預期輸入/輸出的
例子(直接使用的地址只,使其更容易想象):
IsWithin("A2", "A1:B3") = True
IsWithin("B1","B1:B2") = True
IsWithin("A3", "A4:C10") = False
IsWithin("A3", "A3") = True
把我的頭,我能想到的一個簡單的方法來做到這一點的頂部:
Function IsWithin(Range1 as Range, Range2 as Range) as Boolean
Dim cell2 as range
For each cell2 in Range2
If cell2.address = Range1.Address then
IsWithin = True
Exit Function
End if
Next
End function
現在是更難的部分和問題。如果我選擇一個在Range2內部出現的合併單元格,我希望它可以算作範圍的一部分(即使合併單元格的某些部分伸出了)。我需要寫什麼才能完成這項工作?
例考慮A1:B3
被合併單元格(仍在發送地址,而不是範圍內的對象,以此來代表它更容易):
IsWithin("A1:B3", "A2:D7") = True
你會一直在測試一個單元格來檢查它是否在一個更大的範圍內? [包括單個單元是較大合併區域的一部分的情況,這意味着整個合併區域被檢查] –