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 对象,因此它可能会起作用,我只是对实现感到模糊。
谢谢!
最佳答案
这是您要找的吗?
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
关于vba - excel vba从selection.address获取行、单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19102847/