|
- 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 & "\模版.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
- .SaveAs ThisWorkbook.Path & "\结果" & vVillage & ".xlsx"
- Next
- .Close False
- End With
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|