Excel VBA从selection.address获取行,单元格值 [英] excel vba getting the row,cell value from selection.address

查看:252
本文介绍了Excel VBA从selection.address获取行,单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

For i = 1 To 20

  '' select the cell in question
  Cells.Find(...).Select

  '' get the cell address

  CellAddr = Selection.Address(False, False, xlR1C1) 



Next

上面是我的代码,用于搜索电子表格以查找特定的字符串,然后选择它.我想使用 Selection.Address 来获取单元格的地址,在这种情况下,它会返回 R [100] C 的内容.有没有一种方法可以将结果拆分为行和列值,以便可以在代码中对其进行操作?我想例如将14行添加到所选单元格的行值中.我相信 CellAddr 将是一个Range对象,所以它可能会起作用,但我只是对实现感到困惑.

The above is my code for searching a spread sheet to find a specific string and then select it. I'd like to get the address of the cell using Selection.Address which, in this case, returns something along the lines of R[100]C. Is there a way I can split that result in to row and column values so I can manipulate them in code? I'd like, for example to add 14 rows to the selected cells row value. I believe CellAddr will be a Range object so it may work I'm just fuzzy on the implementation.

谢谢!

推荐答案

Dim f as Range

Set f=ActiveSheet.Cells.Find(...)

If Not f Is Nothing then
    msgbox "Row=" & f.Row & vbcrlf & "Column=" & f.Column
Else
    msgbox "value not found!"
End If

这篇关于Excel VBA从selection.address获取行,单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆