跳到主要內容

如何在Excel中獲取活動單元格的地址?

使用Microsoft Excel時,您可以在公式欄左側列出的名稱框中輕鬆獲得當前選定單元格的位置。 但是,如果命名該單元格,則無法基於“名稱框”上的顯示來檢查其位置。 如果要直接顯示活動單元的完整地址,或顯示指定單元中活動單元的地址,該怎麼辦? 在本教程中,我們將向您展示如何使用公式和VBA方法輕鬆獲取活動單元格的地址。

使用公式獲取活動單元格的地址
使用VBA代碼獲取活動單元的地址
使用VBA代碼顯示指定單元中活動單元的地址
使用出色的工具動態顯示活動單元的地址


使用公式獲取活動單元格的地址

在本節中,我們將為您提供輕鬆獲取活動單元格地址的公式。

1.選擇一個單元使其激活。

2.在其中輸入以下公式,然後按 Enter 鍵。

=ADDRESS(ROW(),COLUMN())

然後,您可以看到當前所選單元格的地址立即顯示在該單元格中。

備註:如果您選擇其他單元格,則地址不會自動更改。 為了在選擇其他單元格時獲得動態地址,請應用以下方法。

動態顯示活動單元格的地址:

增強的編輯欄 的效用 Excel的Kutools 幫助在Excel中的工作表中動態顯示活動單元格的地址。 此外,您可以直接在窗口中查看和編輯選擇的單元格內容,如下面的演示所示。
立即下載並嘗試! (30 天免費試用)


使用VBA代碼獲取活動單元的地址

您還可以使用VBA代碼獲取活動單元的地址。 請執行以下操作。

1。 按 其他 + F11 同時打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口,在左窗格中雙擊當前使用工作表的名稱以打開代碼編輯器,然後將下面的VBA代碼複製並粘貼到代碼編輯器中。

VBA代碼:獲取活動單元的地址

Sub selectRange()
	MsgBox ActiveCell.Address
End Sub

3。 然後點擊 按鈕運行代碼。

4.然後將彈出一個對話框,其中列出了活動單元的地址。


使用VBA代碼顯示指定單元中活動單元的地址

在另一種情況下,您希望活動單元格的地址顯示在指定的單元格中。 每次從一個單元格移動到另一個單元格時,該單元格地址都會自動更改並顯示在指定的單元格中。 請執行以下操作。

1.請打開 Microsoft Visual Basic for Applications 通過按下窗口 其他 + F11 在同一時間。

2.雙擊左窗格中的工作表名稱以打開代碼編輯器,然後將以下代碼複製並粘貼到其中。

VBA代碼:顯示指定單元格中活動單元格的地址

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
	Range("A1").Value = ActiveCell.Address
End Sub

備註:A1是您要放置活動單元格地址的單元格,您可以根據自己的需要將其更改為指定的單元格。

3。 然後點擊 文件 > 關閉並返回到Microsoft Excel 退出 Microsoft Visual Basic for Applications 窗口。

您可以在單元格A1上看到活動單元格的地址,並且該地址將根據活動單元格的變化而自動更改。 看截圖:


使用出色的工具動態顯示活動單元的地址

如果要在工作表中動態顯示活動單元格的地址,強烈建議您 增強的編輯欄 的工具 Excel的Kutools。 讓我們看看該工具如何在工作表中動態顯示活動單元格的地址。

申請前 Excel的Kutools首先下載並安裝.

1。 點擊 庫工具 > 顯示隱藏 > 增強的編輯欄 啟用該功能。

從現在開始,每次單擊單元格時,都會彈出“增強的編輯欄”窗口。 原始單元格的地址將顯示在窗口底部。
保養竅門:您可以直接在窗口中直接查看和編輯單元格內容。

  如果您想免費試用(30天)此實用程序, 請點擊下載,然後按照上述步驟進行操作。


最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (5)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Bom dia,
Excelente formula para exibir a célula ativa.
Mas estou precisando utilizar o "conteúdo" de uma célula ativa dentro de uma formula SE.
Entao:

Se
"celula_ativa" = "aluno"
Retorna a seguinte informação "XXXX"
OU se for "professor"
Retorna a seguinte informação "YYYY"

Vc consegue me ajudar com isso, por favor?
This comment was minimized by the moderator on the site
I am fairly new to writing VBA.
Instead of reporting the message box with activated cell address, I would like to pull the cell address of an activated cell from my vba code and store it in a table/other location on the sheet for each iteration that my for loop takes.

How would I go about completing this task?


Regards,
This comment was minimized by the moderator on the site
The first example does not display the address of the active cell but of the cell containing the formula. If you were to select a different cell the address would not change.
Actually this is probably more useful information than gathering the active cell's address and harder to find if you need it. I was looking how to do this using VBA and could not find it for a while so I will include it here:

Application.Caller.Address

That will give you the address of the cell calling the function and not the active cell, useful for relative references.
This comment was minimized by the moderator on the site
Hello,

Displaying the active cell reference is helpful. But how do I actually use that value? I'm reading exams, and have six columns (of which two will get filled in). The student name is in column A; I can extract the family name: LEFT(A7,(FIND(",")A7)-1))) [where A7 is the current address]. I can use the code for displaying the current active cell address provided above:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Range("A1").Value = ActiveCell.Address
End Sub

But what I really want to do is have the cursor being somewhere in the current row (C3:H3), and extract the family name of the current student. Example:

A B C D E F G H
1 Name ID 1 2 3 4 5 6

2 Smith, John 1234567

When the active cell is between C1 and H1, I want to extract the student name from A2 ("Smith, John") [using LEFT(A2,(FIND(",")A2)-1)))], but with the values for the address supplied from the code above.

Any suggestions would be welcome.


Bill
This comment was minimized by the moderator on the site
Dear Bill,
If you want to use the cell reference of active cell, please apply below VBA code.
(The active cell reference will be displayed in cell A1. Then you can copy the cell reference directely in A1 or do other operations as you need.)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
If (Target.Count = 1) And (Intersect(Target, Range("A1")) Is Nothing) Then
Range("A1").Value = ActiveCell.Address
End If
End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations