1. Trang chủ
  2. » Công Nghệ Thông Tin

DÙNG VBA ĐIỀU KHIỂN PIVOT TABLE ĐỂ TẠO BÁO CÁO ppsx

8 548 2
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 8
Dung lượng 92,39 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chuyển vị trí fields từ Area này qua Area khác PHP Code: With ActiveSheet.PivotTables"" .PivotFields"".Orientation = xlRowField 'Row Area' .PivotFields"".Orientation = xlColumnField '

Trang 1

DÙNG VBA ĐIỀU KHIỂN PIVOT

TABLE ĐỂ TẠO BÁO CÁO

I Điều khiển các chức năng cơ bản và nâng cao:

1 Hoán đổi vị trí các fields trong cùng Area

PHP Code:

With ActiveSheet.PivotTables("<PivotTableName>")

.PivotFields("<FieldName>").Position = IIf(.Position = 1, 2, 1)

' Dời Row field qua trái hoặc Column Field lên trên:'

.PivotFields("<FieldName1>").Position = Position - 1

' Dời Row field qua phải hoặc Column Field xuống dưới:'

.PivotFields("<FieldName2>").Position = Position + 1

End With

Trang 2

2 Chuyển vị trí fields từ Area này qua Area khác

PHP Code:

With ActiveSheet.PivotTables("<PivotTableName>")

.PivotFields("<FieldName1>").Orientation = xlRowField 'Row Area'

.PivotFields("<FieldName2>").Orientation = xlColumnField 'Column Area'

.PivotFields("<FieldName3>").Orientation = xlPageField 'Page Area'

End With

3 Thêm & thay đổi dữ liệu cần phần tích trong Data Area

PHP Code:

With ActiveSheet.PivotTables("<PivotTableName>")

.PivotFields("Alias of <FieldName1>").Orientation = xlHidden 'gỡ field ra kh

ỏi Data Area'

Trang 3

.AddDataField ActiveSheet.PivotTables("<PivotTableName>").PivotFields("

<FieldName2>"), _

"Alias of <FieldName2>", xlSum/ xlMax/ xlMin/ 'Thêm field vào Data Ar ea'

End With

4 Show - Hide GrandTotal

PHP Code:

With ActiveSheet.PivotTables("PivotTable1")

RowGrand = True/ False

.ColumnGrand = True/ False

End With

5 Filter single selection

PHP Code:

ActiveSheet.PivotTables("<PivotTableName>").PivotFields("<FieldName>").Cur rentPage = <FieldItem>

6 Filter Multiple selection:

Trang 4

PHP Code:

With ActiveSheet.PivotTables("<PivotTableName>").PivotFields("<FieldName>" )

For i = 1 To PivotItems.Count

With PivotItems(i)

Visible = (Condition1 And/Or Condition2 And/Or Condition3 )

End With

Next

End With

7 Thay đổi field setting

PHP Code:

With ActiveSheet.PivotTables("PivotTable1").PivotFields(CurrentField)

' Sum:'

Calculation = xlSum

'Max:'

Trang 5

Calculation = xlMax

'Mức tăng giảm so với kỳ trước:'

.Calculation = xlDifferenceFrom

.BaseField = "Nam"

.BaseItem = "(previous)"

.NumberFormat = "#,###"

'Mức tăng giảm so với kỳ gốc (2000):'

.Calculation = xlDifferenceFrom

.BaseField = "Nam"

.BaseItem = "2000"

.NumberFormat = "#,###"

'Tỷ lệ tăng giảm so với kỳ trước:'

.Calculation = xlPercentDifferenceFrom

.BaseField = "Nam"

.BaseItem = "(previous)"

Trang 6

'Tỷ lệ tăng giảm so với kỳ gốc (2000):'

.Calculation = xlPercentDifferenceFrom

.BaseField = "Nam"

.BaseItem = "2000"

.NumberFormat = "0.00%"

'Tỷ lệ thành phần trong cột:'

.Calculation = xlPercentOfColumn

'Tỷ lệ thành phần trong hàng:'

.Calculation = xlPercentOfRow

'Tỷ lệ thành phần trong cả bảng:'

.Calculation = xlPercentOfTotal

'Excel 2010:Tỷ lệ thành phần so với subtotal Dòng (parent Row)'

.Calculation = xlPercentOfParentRow

'Excel 2010:Tỷ lệ thành phần so với subtotal cột (parent Column)'

.Calculation = xlPercentOfParentColumn

Trang 7

End With

8 Group trường ngày tháng:

PHP Code:

'Group theo tháng:'

[C16].Group Start:=True, End:=True, Periods:=Array(False, False, False _

, False, True, False, False)

'Group theo quý'

[C16].Group Start:=True, End:=True, Periods:=Array(False, False, False, _

False, False, True, False)

'Group theo quý và tháng (2 cấp)'

[C16].Group Start:=True, End:=True, Periods:=Array(False, False, False, _

False, True, True, False)

'Group theo 6 tháng (tức group theo ngày, 183 ngày)'

[C16].Group Start:=39448, End:=39813, By:=183, Periods:=Array(False, _

False, False, True, False, False, False)

Trang 8

II Sử dụng các control của Form và của Control toolbox:

- OptionButton

- Groupbox

- Checkbox

- Toggle Button

- Combobox (Form Control)

- Combobox (ActiveX control)

- Command Button

Ngày đăng: 07/08/2014, 17:21

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm