phamvanan88
Thành viên mới

- Tham gia
- 15/10/14
- Bài viết
- 23
- Được thích
- 0
Hi, mình có trường value trong pivottable, mình cần thay đổi linh hoạt các giá trị cần lọc ở trường này, thay vì phải kéo thả.
Mình có tạo 1 option box để tùy chọn 1 giá trị max of smax, hoặc 1 giá trị max of scurrent, hoặc cả 2: như hình dưới
- Hiện tại mình có dùng dòng lênh dưới đây để thử thêm và bớt giá trị vào trường value:
If Sheet2.Range("L1") = 1 Then ' them smax
pv6.PivotFields("Max of Scurrent").Orientation = xlHidden
pv6.PivotFields("Max of Smax").Orientation = xlHidden
pv6.AddDataField pv6.PivotFields("Smax"), "Max of Smax", xlMax
ElseIf Sheet2.Range("L1") = 2 Then ' them scurrent
pv6.PivotFields("Max of Scurrent").Orientation = xlHidden
pv6.PivotFields("Max of Smax").Orientation = xlHidden
pv6.AddDataField pv6.PivotFields("Scurrent"), "Max of Scurrent", xlMax
Else ' them ca smax va scurrent
pv6.AddDataField pv6.PivotFields("Scurrent"), "Max of Scurrent", xlMax
pv6.AddDataField pv6.PivotFields("Smax"), "Max of Smax", xlMax
End If
Ý em là trước khi thêm gì vào thì em gỡ cả 2 giá trị smax và scurrent ra, xong rồi mới chèn lệnh thêm ở dưới, tuy nhiên hiện tại thực hiện lệnh nó báo lỗi, các bác xem giúp em khắc phục như nào ah.
Thanks.
Mình có tạo 1 option box để tùy chọn 1 giá trị max of smax, hoặc 1 giá trị max of scurrent, hoặc cả 2: như hình dưới


- Hiện tại mình có dùng dòng lênh dưới đây để thử thêm và bớt giá trị vào trường value:
If Sheet2.Range("L1") = 1 Then ' them smax
pv6.PivotFields("Max of Scurrent").Orientation = xlHidden
pv6.PivotFields("Max of Smax").Orientation = xlHidden
pv6.AddDataField pv6.PivotFields("Smax"), "Max of Smax", xlMax
ElseIf Sheet2.Range("L1") = 2 Then ' them scurrent
pv6.PivotFields("Max of Scurrent").Orientation = xlHidden
pv6.PivotFields("Max of Smax").Orientation = xlHidden
pv6.AddDataField pv6.PivotFields("Scurrent"), "Max of Scurrent", xlMax
Else ' them ca smax va scurrent
pv6.AddDataField pv6.PivotFields("Scurrent"), "Max of Scurrent", xlMax
pv6.AddDataField pv6.PivotFields("Smax"), "Max of Smax", xlMax
End If
Ý em là trước khi thêm gì vào thì em gỡ cả 2 giá trị smax và scurrent ra, xong rồi mới chèn lệnh thêm ở dưới, tuy nhiên hiện tại thực hiện lệnh nó báo lỗi, các bác xem giúp em khắc phục như nào ah.
Thanks.