获取当前单元格 VBA excel 的正确单元格名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26967892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:16:03  来源:igfitidea点击:

Getting Right Cell Name of current Cell VBA excel

vbaexcel-vbaexcel

提问by Addy

I have current cell name like B7i want to get cell name of the cell right to current cell for example in this case the result will be C7. How can I achieve this This is what I have tired but its not working

我有当前的单元格名称,例如B7我想将单元格的单元格名称与当前单元格相关联,例如在这种情况下,结果将是C7. 我怎么能做到这一点这是我累了但它不起作用

CellName = "B7"
ValueCellName = Right(Range(CellName)).name

回答by rusk

Try using offset function:

尝试使用偏移功能:

valuecellname = Range(cellname).Offset(0, 1).Address

回答by Siddharth Rout

Is this what you are trying?

这是你正在尝试的吗?

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