【发布时间】:2014-11-17 07:52:43
【问题描述】:
我有当前单元格名称,例如B7 我想获取当前单元格的单元格名称,例如在这种情况下,结果将是C7。我怎样才能做到这一点
这是我累了,但它不起作用
CellName = "B7"
ValueCellName = Right(Range(CellName)).name
【问题讨论】:
我有当前单元格名称,例如B7 我想获取当前单元格的单元格名称,例如在这种情况下,结果将是C7。我怎样才能做到这一点
这是我累了,但它不起作用
CellName = "B7"
ValueCellName = Right(Range(CellName)).name
【问题讨论】:
尝试使用偏移功能:
valuecellname = Range(cellname).Offset(0, 1).Address
【讨论】:
这是你正在尝试的吗?
Sub Sample()
Debug.Print GetrightCell("B7")
Debug.Print GetrightCell("XFD7")
Debug.Print GetrightCell("ADIL1234")
End Sub
'~~> Function returns the right cell if there is one!
Function GetrightCell(CellName As String) As String
On Error GoTo Whoa
If Range(CellName).Column <> Columns.Count Then
GetrightCell = Range(CellName).Offset(0, 1).Address
Else
GetrightCell = "There are no more cells to the right of this cell"
End If
Exit Function
Whoa:
GetrightCell = "Invalid Cell Name"
End Function
【讨论】: