|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Option Explicit
- Sub PickData()
- On Error Resume Next
- Dim strPath, wbkTemp As Workbook, wstTemp As Worksheet
- Dim rngTemp As Range, strAdd$, i%, j%, arrTemp(1 To 999, 1 To 18)
- strPath = Application.GetOpenFilename(FileFilter:="Excel文件(*.xls;*.xlsx;*.xlsm),*.xls;*.xlsx;*.xlsm", Title:="请选择文件——")
- If strPath = False Then Exit Sub
- Set wbkTemp = Workbooks.Open(Filename:=strPath, UpdateLinks:=False, ReadOnly:=True)
- 'wbkTemp.Activate
- With ThisWorkbook.Sheets("Sheet1")
- For Each wstTemp In wbkTemp.Sheets
- Set rngTemp = wstTemp.Cells.Find("姓名", LookIn:=xlValues, LookAt:=xlWhole)
- If Not rngTemp Is Nothing Then
- strAdd = rngTemp.Address
- Do
- i = i + 1
- j = rngTemp.Row
- arrTemp(i, 1) = i + IIf(IsNumeric(.[A65536].End(xlUp).Value), .[A65536].End(xlUp).Value, 0) '序号
- arrTemp(i, 2) = "" '个人编号
- arrTemp(i, 3) = Replace(wstTemp.Cells(j, 3), " ", "") '姓名
- arrTemp(i, 4) = wstTemp.Cells(j + 18, 8) '申报收入
- arrTemp(i, 5) = wstTemp.Cells(j + 5, 10) '一月
- arrTemp(i, 6) = wstTemp.Cells(j + 6, 10) '二月
- arrTemp(i, 7) = wstTemp.Cells(j + 7, 10) '三月
- arrTemp(i, 8) = wstTemp.Cells(j + 8, 10) '四月
- arrTemp(i, 9) = wstTemp.Cells(j + 9, 10) '五月
- arrTemp(i, 10) = wstTemp.Cells(j + 10, 10) '六月
- arrTemp(i, 11) = wstTemp.Cells(j + 11, 10) '七月
- arrTemp(i, 12) = wstTemp.Cells(j + 12, 10) '八月
- arrTemp(i, 13) = wstTemp.Cells(j + 13, 10) '九月
- arrTemp(i, 14) = wstTemp.Cells(j + 14, 10) '十月
- arrTemp(i, 15) = wstTemp.Cells(j + 15, 10) '十一月
- arrTemp(i, 16) = wstTemp.Cells(j + 16, 10) '十二月
- arrTemp(i, 17) = wstTemp.Cells(j + 17, 10) '合计
- arrTemp(i, 18) = "" '差异
- Set rngTemp = wstTemp.Cells.FindNext(rngTemp)
- Loop While Not rngTemp Is Nothing And strAdd <> rngTemp.Address
- End If
- Next
- .[A65536].End(xlUp).Offset(1, 0).Resize(i, 1).EntireRow.Insert
- .[A65536].End(xlUp).Offset(1, 0).Resize(i, 18) = arrTemp
- End With
- wbkTemp.Close savechanges:=False
- Set wbkTemp = Nothing
- End Sub
复制代码 |
|