How do I get a range's address including the worksheet name, but not the workbook name, in Excel VBA?

前端 未结 11 1492
眼角桃花
眼角桃花 2020-12-25 10:34

If I have a Range object--for example, let\'s say it refers to cell A1 on a worksheet called Book1. So I know that calling Address()

11条回答
  •  醉酒成梦
    2020-12-25 10:54

    [edit on 2009-04-21]

        As Micah pointed out, this only works when you have named that
        particular range (hence .Name anyone?) Yeah, oops!

    [/edit]

    A little late to the party, I know, but in case anyone else catches this in a google search (as I just did), you could also try the following:

    Dim cell as Range
    Dim address as String
    Set cell = Sheet1.Range("A1")
    address = cell.Name
    

    This should return the full address, something like "=Sheet1!$A$1".

    Assuming you don't want the equal sign, you can strip it off with a Replace function:

    address = Replace(address, "=", "")
    

提交回复
热议问题