|
本帖最后由 ning84 于 2018-2-4 21:04 编辑
Excel 如何汇总多表-Excel数据透视表-ExcelHome技术论坛 - http://club.excelhome.net/thread-1310482-1-1.html
想用透视功能实现下面多表合一,没有成功。现在采用的是VBA方法。
请问,透视表的多表合一,对多表有什么要求。
- Private Sub DEL()
- Dim RngArr(3) As Range
- Dim Rng As Range, oRng As Range
- Dim oRng1 As Range, oRng2 As Range
- ''
- Set Rng = Range("A:F")
- With Rng
- .ClearContents
- .UnMerge
- .Orientation = 0
- .Font.Size = 10
- .Borders.LineStyle = xlNone
- End With
- ''
- Set Rng = Cells(2, "I").CurrentRegion
- Set RngArr(0) = Rng
- ''Debug.Print Rng.Address
- Set Rng = Rng(2, 1).Resize(Rng.Rows.Count - 1, 1)
- Dim ii, nn, nn1
- For ii = 2 To 4
- Set RngArr(ii - 1) = Range(Rng(, ii).Formula).CurrentRegion
- 'Debug.Print RngArr(ii - 1).Address
- Next ii
- rr = 3
- nn = RngArr(0).Rows.Count
- nn1 = Rng.Rows.Count
- ''
- Dim Row: Row = 2
- For ii = 0 To nn
- Set Rng = Cells(Row, 1)
- For kk1 = 0 To UBound(RngArr)
- Set oRng = RngArr(kk1)
- 'Debug.Print oRng.Address
- If kk1 = 0 Then
- Set oRng1 = Cells(Row + 1, 1).Resize(, RngArr(1).Columns.Count + 1)
- ''
- With oRng1
- .MergeCells = True
- .Borders.LineStyle = xlContinuous
- .HorizontalAlignment = xlCenter
-
- End With
- oRng1 = "= " & oRng(ii + 2, 1).Address
- ''
- Set oRng2 = Cells(Row + 2, 1).Resize(UBound(RngArr) * 2, 1)
- With oRng2
- .MergeCells = True
- .Orientation = 90
- .Borders.LineStyle = xlContinuous
- End With
- oRng2 = "= " & oRng(ii + 2, 1).Address
- Set oRng1 = oRng1.Resize(oRng2.Rows.Count + 1, oRng1.Columns.Count)
- oRng1.Borders.LineStyle = xlContinuous
- Row = Row + 2
- Else
- For kk = 2 To 2
- For jj = 1 To oRng.Columns.Count
- If oRng(kk, jj) <> "" Then
- Cells(Row, jj + 1) = "= " & oRng(kk, jj).Address
- End If
- Cells(Row + 1, jj + 1) = "= " & oRng(ii + 3, jj).Address
- Next jj
- Row = Row + 1
- Next kk
- Row = Row + 1
- End If
- Next kk1
- 'Row = Row - 1
- Next ii
- End Sub
复制代码
|
|