|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这个问题终于搞定,可以根据需要选择前?家,后?家,同时降序排列。SQL+VBA+PivotFields(X).AutoShow,AutoSort
也可也选择库存最前或最后的n家,只要在选择字段时,选择库存字段即可。
将代码略作修改,更方便,如下:
[attach]635531[/attach-
- Private Sub CommandButton1_Click()
- StrUpDown = MsgBox("最前请选yes,最后请no", vbYesNo)
- Select Case StrUpDown
- Case vbYes
- intUp = Application.InputBox(prompt:="前?家", Type:=1)
- Set tempRange = Application.InputBox(prompt:="请选择引用字段的单元格,只选一个!", Type:=8)
- strField = tempRange.Cells(1, 1).Value
- With ThisWorkbook.Sheets("Total").PivotTables("PVT1").PivotFields("商品编码")
- .AutoShow xlAutomatic, xlTop, intUp, strField
- .AutoSort xlDescending, strField
- End With
- CommandButton1.Caption = Trim(strField) & "最大" & intUp & "家"
- Set tempRange = Nothing
- Case vbNo
- intDown = Application.InputBox(prompt:="后?家", Type:=1)
- Set tempRange = Application.InputBox(prompt:="请选择引用字段的单元格,只选一个!", Type:=8)
- strField = tempRange.Cells(1, 1).Value
- With ThisWorkbook.Sheets("Total").PivotTables("PVT1").PivotFields("商品编码")
- .AutoShow xlAutomatic, xlBottom, intDown, strField
- .AutoSort xlDescending, strField
- End With
- CommandButton1.Caption = Trim(strField) & "最小" & intDown & "家"
- Set tempRange = Nothing
- End Select
复制代码
[ 本帖最后由 masterexcel 于 2009-12-27 18:21 编辑 ] |
|