|
此代码是将透视表数据批量填到模板中,主要填到以下三个表
问题一
外承包面积复制到出租经营面积中,但是复制的列错误了
问题二
部分类型不复制,如公共管理与公共服务用地
望各位大侠指正
附代码
- Sub 生成数据()
- Dim dicData As Object
- Dim vData As Variant, nRow As Integer, vFill As Variant
- Dim vVillage As Variant, vType As Variant, sData As String, sType As String
- Dim wSH As Worksheet, vSH As Variant
- Dim dicSH As Object, vCol As Variant, nCol As Integer
-
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
-
- vData = Sheet1.UsedRange.Value '已使用区域的范围
- Set dicData = CreateObject("Scripting.Dictionary")
- For nRow = 1 To UBound(vData) '行数
- sData = Trim(vData(nRow, 1)) '村名
- vType = Trim(vData(nRow, 2)) '资源类型
- If sData = "" Or sData Like "*村" Then
- If sData <> "" Then
- vVillage = sData
- Set dicData(vVillage) = CreateObject("Scripting.Dictionary")
- End If
- If vType <> "" Then dicData(vVillage)(vType) = Val(vData(nRow, 3))
- End If
- Next
- With Workbooks.Open(ThisWorkbook.Path & "\附件2农村集体资产清产核资汇总表(定稿).xlsx")
- Set dicSH = CreateObject("Scripting.Dictionary")
- For Each wSH In .Sheets
- vSH = vSH + 1
- If wSH.Name Like "*农用地*" Or wSH.Name Like "*建设用地*" Or wSH.Name Like "*未利用地*" Then
- Set dicSH(vSH) = CreateObject("Scripting.Dictionary")
- vData = wSH.UsedRange.Value
- For nRow = 9 To UBound(vData)
- If vData(nRow, 1) Like "相关事项说明*" Then
- nRow = nRow - 1
- Exit For
- Else
- sType = Trim(Replace(vData(nRow, 2), " ", ""))
- For Each vType In dicData(vVillage).Keys
- If sType Like "*" & vType & "*" Then
- vData(nRow - 8, 1) = vType
- Exit For
- End If
- Next
- End If
- Next
- If nRow > UBound(vData) Then nRow = nRow - 1
- ReDim vFill(1 To nRow - 8, 1 To UBound(vData, 2) - 2)
- dicSH(vSH)("填写数据") = vFill
- ReDim Preserve vData(1 To UBound(vData), 1 To 1)
- vData = Application.WorksheetFunction.Transpose(vData)
- ReDim Preserve vData(1 To nRow - 8)
- If wSH.Name Like "*农用地*" Then
- dicSH(vSH)("填数据列") = Array(2, 9)
- ElseIf wSH.Name Like "*建设用地*" Then
- dicSH(vSH)("填数据列") = Array(2, 13)
- Else
- dicSH(vSH)("填数据列") = Array(1)
- End If
- dicSH(vSH)("数据") = vData
- dicSH(vSH)("最后一行") = nRow
- End If
- Next
- For Each vVillage In dicData.Keys
- sData = "临邑 乡镇(街)" & vVillage & "(居) 组 201 年 月 日 单位:亩、立方米、元"
- For Each vSH In dicSH.Keys
- vCol = dicSH(vSH)("填数据列")
- nRow = dicSH(vSH)("最后一行")
- vData = dicSH(vSH)("数据")
- vFill = dicSH(vSH)("填写数据")
- For nRow = 1 To UBound(vFill)
- vType = vData(nRow)
- If dicData(vVillage).Exists(vType) Then
- nCol = 0
- Do While nCol <= UBound(vCol)
- If nRow > 1 Then vFill(nRow, vCol(nCol)) = dicData(vVillage)(vType)
- vFill(1, vCol(nCol)) = vFill(1, vCol(nCol)) + dicData(vVillage)(vType)
- nCol = nCol + 1
- Loop
- End If
- Next
- With .Sheets(vSH)
- .[A4] = sData
- .[c9].Resize(UBound(vFill), UBound(vFill, 2)) = vFill
- End With
-
- Next
- .Sheets("资源清查明细表(农用地)").[d10] = "=SUM(RC[3],RC[7])"
- .Sheets("资源清查明细表(农用地)").[d11] = "=SUM(RC[3],RC[7])"
- .Sheets("资源清查明细表(农用地)").[d12] = "=SUM(RC[3],RC[7])"
- .Sheets("资源清查明细表(农用地)").[d13] = "=SUM(RC[3],RC[7])"
- .Sheets("资源清查明细表(农用地)").[d14] = "=SUM(RC[3],RC[7])"
- .Sheets("资源清查明细表(农用地)").[d15] = "=SUM(RC[3],RC[7])"
- .Sheets("资源清查明细表(农用地)").[d9] = "=SUM(R[1]C:R[7]C)"
- .Sheets("资源清查明细表(农用地)").[g9] = "=SUM(R[1]C:R[7]C)"
- .Sheets("资源清查明细表(农用地)").[k9] = "=SUM(R[1]C:R[7]C)"
- .Sheets("资源清查明细表(农用地)").[m9] = "=SUM(R[1]C:R[7]C)"
- .Sheets("资源清查明细表(农用地)").[c9] = "=SUM(RC[1],RC[10])"
- .Sheets("资源清查明细表(农用地)").[c10] = "=SUM(RC[1],RC[10])"
- .Sheets("资源清查明细表(农用地)").[c11] = "=RC[1]"
- .Sheets("资源清查明细表(农用地)").[c12] = "=RC[1]"
- .Sheets("资源清查明细表(农用地)").[c13] = "=RC[1]"
- .Sheets("资源清查明细表(农用地)").[c14] = "=RC[1]"
- .Sheets("资源清查明细表(农用地)").[c15] = "=RC[1]"
- .Sheets("资源清查明细表(农用地)").[c16] = "=RC[1]"
- .Sheets("资源清查明细表(建设用地)").[d9] = "=SUM(R[1]C:R[6]C)"
- .Sheets("资源清查明细表(建设用地)").[o9] = "=SUM(R[1]C:R[6]C)"
- .Sheets("资源清查明细表(建设用地)").[c9] = "=RC[1]"
- .Sheets("资源清查明细表(建设用地)").[c10] = "=RC[1]"
- .Sheets("资源清查明细表(建设用地)").[c11] = "=RC[1]"
- .Sheets("资源清查明细表(建设用地)").[c12] = "=RC[1]"
- .Sheets("资源清查明细表(建设用地)").[c13] = "=RC[1]"
- .Sheets("资源清查明细表(建设用地)").[c14] = "=RC[1]"
- .Sheets("资源清查明细表(建设用地)").[c15] = "=RC[1]"
- .SaveAs ThisWorkbook.Path & "\结果" & vVillage & ".xlsx"
- Next
- .Close False
- End With
- MsgBox ("成功!")
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
-
- End Sub
复制代码
|
|