我有当前的单元格名称B7
我希望将单元格的单元格名称设置为当前单元格,例如在这种情况下,结果将为C7
。我怎样才能做到这一点
这是我累了,但它不起作用
CellName = "B7"
ValueCellName = Right(Range(CellName)).name
答案 0 :(得分:5)
尝试使用偏移功能:
valuecellname = Range(cellname).Offset(0, 1).Address
答案 1 :(得分:1)
这是你在尝试的吗?
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