使用活動單元格查找範圍名稱 (Find Range Name Using Active Cell)


問題描述

使用活動單元格查找範圍名稱 (Find Range Name Using Active Cell)

我是 VBA 編程的初學者。

我有一個單元格是命名範圍的一部分。使用該活動單元格,我希望能夠找到該單元格所屬的範圍,並將其作為 Range 對像傳遞給 VBA 函數或子例程。

任何人都可以為我提供有關如何操作的指導繼續,或者這不可能?

提前致謝!


參考解法

方法 1:

Here is a simple example.

The code checks if the selected cell is part of a named range. If so, the named range is passed to a function:

Sub Main()
    Dim nm As Integer

    For nm = 1 To ActiveWorkbook.Names.Count
       If Not Intersect(Selection, Range(ActiveWorkbook.Names(nm).Name)) Is Nothing Then
            Debug.Print MyFunc(Range(ActiveWorkbook.Names(nm).Name)) // Prints TRUE or FALSE
       End If
    Next nm
End Sub

Function MyFunc(Named_Range As Range) As Boolean
    MyFunc = Named_Range.Cells.Count > 2  ~~>Courtesy of `Thomas Inzina`
End Function

(by sglowatsAlex P)

參考文件

  1. Find Range Name Using Active Cell (CC BY‑SA 2.5/3.0/4.0)

#range #excel #vba






相關問題

tcng - 匹配“if”語句中的端口範圍 (tcng - match port range in "if" statement)

如何在 MATLAB 中將自定義顏色範圍與顏色條相結合? (How to combine a custom color range with colorbar in MATLAB?)

如何檢查單個值以查看它是否包含 18 個值之一 (How do I check a single value to see if it contains one of 18 values)

選擇單元格時獲取 excel 以運行 vba 代碼的問題 (Problems getting excel to run vba code when a cell is selected)

對包含 EXCEL 中文本的單元格進行數學運算 (Do math on cells also contaning text in EXCEL)

autohotkey:添加連續的數字範圍 (autohotkey: add consecutive range of numbers)

如何將一種功能集成到另一種功能中 (How to integrate one function into another one)

使用活動單元格查找範圍名稱 (Find Range Name Using Active Cell)

基於 C++ 非迭代器的範圍庫? (C++ non-iterator based range library?)

用D語言從一個範圍內製作數組 (Make array from a range in D language)

Internet Explorer 上的自定義範圍滑塊問題 (Custom range slider issue on Internet Explorer)

如何從列表中刪除一系列值並使上述減去的範圍在新列表中不可用? (How to delete a range of values from a list and make the aforementioned subtracted range unavailable in a new list?)







留言討論