问题描述
我的excel中有一个Slicer,具有以下2个值
I have a Slicer in my excel with the following 2 values
添加客户添加供应商
单击这些值时,我想打开2个不同的表单.谁能帮我这个忙.
I want to open 2 different forms when click on those value. Can anyone please help me with this.
推荐答案
是的,您可以在切片器点击时调用不同的表单,请检查以下代码.希望它能满足您的要求,如果不是,您可以根据自己的要求进行更改.
Yes, you can call different forms on slicer clicks, check the below code. Hope it suits your requirement and if not you can use to change as per your requirement.
在Worksheet_PivotTableUpdate
事件中编写代码时,在每个切片器上单击都会调用此事件.
On Writing your code in Worksheet_PivotTableUpdate
event, on each slicer click this event will get called.
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
If ActiveWorkbook.SlicerCaches("Slicer_Region").SlicerItems("East").Selected = True Then
UserForm1.Show
ElseIf ActiveWorkbook.SlicerCaches("Slicer_Region").SlicerItems("West").Selected = True Then
UserForm2.Show
End If
End Sub
在哪里, Slicer_Region =要在公式中使用的名称"
您可以通过右键单击切片器并单击切片器设置来获得此名称.并找到要在公式中使用的名称.
You can get this name by right click on slicer and click slicer settings. and find the name to use in formula.
东西方=切片机名称"
要为其调用不同的表单.
For which you want to call different forms.
这篇关于如何在Excel VBA中的切片器中单击值时运行宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!