我有一个动态列表框,它将显示数据透视表中的值。
我有多个选择列表框设置。
是否有一种方法可以将多选复选框与列表框连接起来,如果我取消选中该复选框,它将从数据透视表筛选器中删除该选择,从而更改下面用户表单中显示的总计?
总成本表
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = Application.Top + Application.Height - Me.Height * 1.08
Me.Left = Application.Left + Application.Width - Me.Width * 1.12
Description = Sheet8.Range("A1").Value
Material = Sheet8.Range("A2").Value
Labor = Sheet8.Range("A3").Value
SubContractor = Sheet8.Range("A4").Value
Equipment = Sheet8.Range("A5").Value
Other = Sheet8.Range("A6").Value
TotalCost = Sheet8.Range("A7").Value
Overhead = Sheet8.Range("A9").Value
Profit = Sheet8.Range("A10").Value
Phoenix = Sheet8.Range("A11").Value
Bond = Sheet8.Range("A12").Value
TotalPrice = Sheet8.Range("A14").Value
DescriptionTotal = Sheet8.Range("B1").Value
MaterialTotal = Sheet8.Range("B2").Value
MaterialTotal = Format(MaterialTotal, "$#,##0.00")
LaborTotal = Sheet8.Range("B3").Value
LaborTotal = Format(LaborTotal, "$#,##0.00")
SubContractorTotal = Sheet8.Range("B4").Value
SubContractorTotal = Format(SubContractorTotal, "$#,##0.00")
EquipmentTotal = Sheet8.Range("B5").Value
EquipmentTotal = Format(EquipmentTotal, "$#,##0.00")
OtherTotal = Sheet8.Range("B6").Value
OtherTotal = Format(OtherTotal, "$#,##0.00")
TotalCostTotal = Sheet8.Range("B7").Value
TotalCostTotal = Format(TotalCostTotal, "$#,##0.00")
OverheadTotal = Sheet8.Range("B9").Value
OverheadTotal = Format(OverheadTotal, "$#,##0.00")
ProfitTotal = Sheet8.Range("B10").Value
ProfitTotal = Format(ProfitTotal, "$#,##0.00")
PhoenixTotal = Sheet8.Range("B11").Value
PhoenixTotal = Format(PhoenixTotal, "$#,##0.00")
BondTotal = Sheet8.Range("B12").Value
BondTotal = Format(BondTotal, "$#,##0.00")
TotalPriceTotal = Sheet8.Range("B14").Value
TotalPriceTotal = Format(TotalPriceTotal, "$#,##0.00")
Dim List As New Collection
Dim Rng As Range
Dim lngIndex As Long
LastRow = Sheet8.Columns("A").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Set Rng = Sheet8.Range("A18:B" & LastRow - 1)
TotalCostList.ColumnCount = 2
With TotalCostList
.ColumnCount = 2
.List = Rng.Value
.BorderStyle = fmBorderStyleSingle
End With
With Me.TotalCostList
For lngIndex = 0 To .ListCount - 1
.List(lngIndex, 1) = Format(.List(lngIndex, 1), "$#,##0.00")
.TextAlign = 1 - frmTextAlignLeft
Next lngIndex
End With
Dim i As Long
For i = 0 To TotalCostList.ListCount - 1
TotalCostList.Selected(i) = True
Next i
End Sub
1条答案
按热度按时间qacovj5a1#
如果我没理解错的话,下面是一个示例子程序,它将根据用户窗体中选中的复选框来筛选数据透视表的页字段。
将所有的Checkboxes的标题设置为ThePivotFieldNameToBeFiltered的透视项名称。checkbox的标题用于筛选透视字段。或者,如果要筛选的透视字段的每个项都是每个checkbox的名称,则在测试子中将
ctrl.caption
更改为ctrl.name
。如果您不想重复userform_initialize过程,请将用于填充userform_initialize中TotalCostList列表框的过程分隔到另一个子进程中,并将该子进程命名为PopulateTotalCostList。但是,如果您可以重复userform_initialize过程,请将
call PopulateTotalCostList
更改为call UserForm_Initialize
为了使sub不会在用户每次选中/取消选中复选框时都运行,请添加一个按钮来调用sub。因此,用户必须在完成选中/取消选中复选框后单击该按钮才能查看结果。