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

前端 未结 11 1462
眼角桃花
眼角桃花 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 11:03

    I found the following worked for me in a user defined function I created. I concatenated the cell range reference and worksheet name as a string and then used in an Evaluate statement (I was using Evaluate on Sumproduct).

    For example:

    Function SumRange(RangeName as range)   
    
    Dim strCellRef, strSheetName, strRngName As String
    
    strCellRef = RangeName.Address                 
    strSheetName = RangeName.Worksheet.Name & "!" 
    strRngName = strSheetName & strCellRef        
    

    Then refer to strRngName in the rest of your code.

提交回复
热议问题