|
本帖最后由 爱吃苹果的女巫 于 2024-9-12 15:08 编辑
算好了张三、李四、王五、赵六的奖金,然后要分发给他们各自确认
现在文件复制已经解决了
但张三文件里,明细那一页不属于张三的行要删掉,这个失败了
麻烦大佬帮忙看看
代码是百度后拼装的......苦命的自学人......
Sub copyfile()
Application.ScreenUpdating = False
Dim oldbook As Workbook
Dim newbook As Workbook
Dim nowbook As Workbook
Dim oldname As String
Dim newName As String
Dim savepath As String
Dim arr(1 To 4) As String
Dim i As Integer
Dim K As Integer
Dim maxrow As Integer
arr(1) = "张三"
arr(2) = "李四"
arr(3) = "王五"
arr(4) = "赵六"
savepath = ThisWorkbook.Path & "\"
oldname = Split(ThisWorkbook.Name, ".")(0)
For i = 1 To 4
newName = arr(i)
ThisWorkbook.SaveCopyAs savepath & oldname & "-" & newName & ".xlsm"
Set nowbook = Workbooks.Open(savepath & oldname & "-" & newName & ".xlsm")
nowbook.Activate
Worksheets("明细").Activate
With ActiveSheet
maxrow = .Cells(.Rows.Count, 1).End(xlUp).Row
End With
For K = maxrow To 2
If Range("B" & K) <> newName Then Rows(K).EntireRow.Delete
Next K
nowbook.Close SaveChanges:=True
Next i
Application.ScreenUpdating = True
End Sub
|
|