跳到主要内容

如何在Excel中获取活动单元格的地址?

使用Microsoft Excel时,您可以在公式栏左侧列出的名称框中轻松获得当前选定单元格的位置。 但是,如果命名该单元格,则无法基于“名称框”上的显示来检查其位置。 如果要直接显示活动单元格的完整地址,或显示指定单元格中活动单元格的地址,该怎么办? 在本教程中,我们将向您展示如何使用公式和VBA方法轻松获取活动单元格的地址。

使用公式获取活动单元格的地址
使用VBA代码获取活动单元的地址
使用VBA代码显示指定单元中活动单元的地址
使用出色的工具动态显示活动单元的地址


使用公式获取活动单元格的地址

在本节中,我们将为您提供轻松获取活动单元格地址的公式。

1.选择一个单元使其激活。

2.在其中输入以下公式,然后按 输入 键。

=ADDRESS(ROW(),COLUMN())

然后,您可以看到当前所选单元格的地址立即显示在该单元格中。

备注:如果您选择其他单元格,则地址不会自动更改。 为了在选择其他单元格时获得动态地址,请应用以下方法。

动态显示活动单元格的地址:

增强的编辑栏 实用程序 Kutools for Excel 帮助在Excel中的工作表中动态显示活动单元格的地址。 此外,您可以直接在窗口中查看和编辑选择的单元格内容,如下面的演示所示。
立即下载并尝试! (30 天免费试用)


使用VBA代码获取活动单元的地址

您还可以使用VBA代码获取活动单元的地址。 请执行以下操作。

1。 按 其他 + F11 同时打开 Microsoft Visual Basic应用程序 窗口。

2.在 Microsoft Visual Basic应用程序 窗口,在左窗格中双击当前使用工作表的名称以打开代码编辑器,然后将下面的VBA代码复制并粘贴到代码编辑器中。

VBA代码:获取活动单元的地址

Sub selectRange()
	MsgBox ActiveCell.Address
End Sub

3.然后点击 运行 按钮运行代码。

4.然后将弹出一个对话框,其中列出了活动单元的地址。


使用VBA代码显示指定单元中活动单元的地址

在另一种情况下,您希望活动单元格的地址显示在指定的单元格中。 每次当您从一个单元格移动到另一个单元格时,单元格地址都会自动更改并显示在指定的单元格中。 请执行以下操作。

1.请打开 Microsoft Visual Basic应用程序 通过按下窗口 其他 + 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应用程序 窗口。

您可以在单元格A1上看到活动单元格的地址,并且该地址将根据活动单元格的变化而自动更改。 看截图:


使用出色的工具动态显示活动单元的地址

如果要在工作表中动态显示活动单元格的地址,强烈建议您 增强的编辑栏 的工具 Kutools for Excel。 让我们看看该工具如何在工作表中动态显示活动单元格的地址。

申请前 Kutools for Excel首先下载并安装.

1。 点击 库工具 > 显示隐藏 > 增强的编辑栏 启用该功能。

从现在开始,每次单击单元格时,都会弹出“增强的编辑栏”窗口。 原始单元格的地址将显示在窗口底部。
Tips:您可以直接在窗口中直接查看和编辑单元格内容。

  如果您想免费试用(30天)此实用程序, 请点击下载,然后按照上述步骤进行操作。


最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 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