数据透视表如果要做成你所说的哪个样子估计比较难,要通达SQL语句做,或者用VBA ,前几天看了一位大侠用VBA做的转置,今天用来练一下手。做了二种方法。- Sub 测试()
- Dim a, b, Arr, Brr(1 To 10000, 1 To 4)
- Arr = Sheet1.Range("a1").CurrentRegion
- For b = 3 To UBound(Arr, 2)
- For a = 2 To UBound(Arr)
- n = n + 1
- Brr(n, 1) = Arr(1, b)
- Brr(n, 2) = Arr(a, 1)
- Brr(n, 3) = Arr(a, 2)
- Brr(n, 4) = Arr(a, b)
- Next
- Next
- Sheet2.Range("a2").Resize(10000, 4) = Brr
- End Sub
复制代码
- select 部门, 项目, [1月] as 金额,"1月" as 月份 from [1$] union all
- select 部门, 项目, [2月] as 金额,"2月" as 月份 from [1$] union all
- select 部门, 项目, [3月] as 金额,"3月" as 月份 from [1$] union all
- select 部门, 项目, [4月] as 金额,"4月" as 月份 from [1$] union all
- select 部门, 项目, [5月] as 金额,"5月" as 月份 from [1$] union all
- select 部门, 项目, [6月] as 金额,"6月" as 月份 from [1$] union all
- select 部门, 项目, [7月] as 金额,"7月" as 月份 from [1$] union all
- select 部门, 项目, [8月] as 金额,"8月" as 月份 from [1$] union all
- select 部门, 项目, [9月] as 金额,"9月" as 月份 from [1$] union all
- select 部门, 项目, [10月] as 金额,"10月" as 月份 from [1$] union all
- select 部门, 项目, [11月] as 金额,"11月" as 月份 from [1$] union all
- select 部门, 项目, [12月] as 金额,"12月" as 月份 from [1$]
复制代码
[ 本帖最后由 suwenkai 于 2011-1-17 16:21 编辑 ] |