我正在尝试在工作表1上有一个单元格返回工作表的名称变量'r1'(在工作表2上)或'r2'(在工作表3上)被引用,如果它们符合资格。我现在拥有的是:
Public Function whichsheet(r1 As Range, r2 As Range) As String
If Application.Sum(r1) > 0 Then
whichsheet = whichsheet & Application.Caller.Worksheet.Name
End If
If Application.Sum(r2) > 0 Then
whichsheet = whichsheet & Application.Caller.Worksheet.Name
End If
End Function
其中Application.Caller.Worksheet.Name当前是占位符,用于提取第一个工作表的名称,“sheet1”而不是“sheet1”和/或“sheet2”。
答案 0 :(得分:4)
以下内容将在传递范围时返回范围的工作表名称。
Public Function whichsheet(r1 As Range, r2 As Range) As String
If Application.Sum(r1) > 0 Then
whichsheet = whichsheet & r1.Parent.Name
End If
If Application.Sum(r2) > 0 Then
whichsheet = whichsheet & r2.Parent.Name
End If
End Function