|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Public Sub 生成津贴文件()
- Dim wb As Workbook, sht As Worksheet
- Dim nWb As Workbook, nSht As Worksheet
- Dim i, j, jSum
- Set wb = Application.ThisWorkbook
- Set sht = wb.Worksheets(1)
- With sht
- erow = .Cells(.Rows.Count, 1).End(xlUp).Row
- ecol = .Cells(1, .Columns.Count).End(xlToLeft).Column
- For j = 5 To ecol
- '一整列求和不为0
- jSum = WorksheetFunction.Sum(.Range(.Cells(2, j), .Cells(erow, j)))
- If WorksheetFunction.Sum(.Range(.Cells(2, j), .Cells(erow, j))) > 0 Then
- Debug.Print j, jSum
- Set nWb = Workbooks.Add
- nWb.SaveAs wb.Path & "" & .Cells(1, j).Value & ".xlsx"
- Set nSht = nWb.Worksheets(1)
- nSht.Range("a1:c1").Value = Array("编号", "姓名", .Cells(1, j).Value)
- r = 1
- For i = 2 To erow
- If .Cells(i, j).Value > 0 Then
- r = r + 1
- nSht.Cells(r, 1).Value = .Cells(i, 3).Value '编号
- nSht.Cells(r, 2).Value = .Cells(i, 4).Value '姓名
- nSht.Cells(r, 3).Value = .Cells(i, j).Value '金额
- End If
- Next i
- nWb.Close True
- End If
- Next j
- End With
- End Sub
复制代码 |
|