我希望我可以发表评论,但我还不能,因为我没有足够的代表点!(不得不重新启动我的帐户!)
我可以建议您在手动钻取任何给定数据点时录制宏,并查看录制的 vba 代码的外观。我想从那里你可以配置你的代码,使你的工作表的名称基于记录代码的某些元素。
因为,我希望这是一个评论,如果它没有帮助,我会删除它。
更新您新发布的答案:
要在用户向下钻取时检查工作表是否已经存在,您可以在获取工作表名称后检查工作表是否存在,如果存在,请选择它,而不是创建新的工作表。否则,您创建它。
请参阅此代码:
Private Sub Workbook_NewSheet(ByVal sh As Object)
Application.ScreenUpdating = False
Dim shtCur As Worksheet
Set shtCur = ActiveSheet
Sheets("DQ Summary").Select
RN = ActiveCell.Row
CN = ActiveCell.Column
SheetName = Cells(RN, 2).Value & " - " & Cells(9, CN).Value
If SheetExists(SheetName) Then
Worksheets(SheetName).Select
Else
shtCur.Move _
After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
shtCur.Name = "SheetName"
End If
Application.ScreenUpdating = True
End Sub
Function SheetExists(wsName As String, Optional wb As Workbook = Nothing) As Boolean
SheetExists = False
Dim WS As Worksheet
If wb Is Nothing Then Set wb = ThisWorkbook
On Error Resume Next
Set WS = wb.Worksheets(wsName)
On Error GoTo 0
If Not WS Is Nothing Then SheetExists = True
End Function