简体   繁体   English

excel vba从selection.address获取行,单元格值

[英]excel vba getting the row,cell value from 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

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 . 我想使用Selection.Address获取单元格的地址,在这种情况下,返回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. 我想,例如在所选单元格行值中添加14行。 I believe CellAddr will be a Range object so it may work I'm just fuzzy on the implementation. 我相信CellAddr将是一个Range对象,所以它可能工作我只是模糊实现。

Thanks! 谢谢!

Is this what you are looking for ? 这是你想要的 ?

Sub getRowCol()

    Range("A1").Select ' example

    Dim col, row
    col = Split(Selection.Address, "$")(1)
    row = Split(Selection.Address, "$")(2)

    MsgBox "Column is : " & col
    MsgBox "Row is : " & row

End Sub
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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM