统计工资
先按照包装、销售、拍照三项进行小计,然后计算总工资。(注:员工姓名一栏应该是可以唯一标示身份的ID)
宏代码如下:
Const N As Integer = 7
Sub calculate()
Dim counter As Integer
Dim flag As Boolean
counter = 2
Worksheets("sheet1").Cells(1, N) = "姓名"
Worksheets("sheet1").Cells(1, N + 1) = "包装工资"
counter = myFun(counter, 5, 2, N + 1)
Worksheets("sheet1").Cells(1, N + 2) = "销售工资"
counter = myFun(counter, 8, 3, N + 2)
Worksheets("sheet1").Cells(1, N + 3) = "拍照工资"
counter = myFun(counter, 5, 4, N + 3)
Worksheets("sheet1").Cells(1, N + 4) = "总工资"
For Index = 2 To counter - 1
With Worksheets("sheet1")
.Cells(Index, N + 4).Value = .Cells(Index, N + 1).Value + .Cells(Index, N + 2).Value + .Cells(Index, N + 3).Value
End With
Next
End Sub
Function myFun(ByVal counter As Integer, ByVal price As Integer, ByVal col As Integer, resultColume As Integer) As Integer
Dim i, k As Integer
Dim Name As String
Dim flag As Boolean
For i = 2 To Worksheets("sheet1").UsedRange.Rows.Count Step 1
Name = Worksheets("sheet1").Cells(i, col).Value
If Len(Name) > 1 Then
flag = False
For k = 2 To counter
If Name = Worksheets("sheet1").Cells(k, N).Value Then
Worksheets("sheet1").Cells(k, resultColume).Value = Worksheets("sheet1").Cells(k, resultColume).Value + price '价格为price
flag = True
Exit For
End If
Next
If flag = False Then
Worksheets("sheet1").Cells(counter, N) = Name
Worksheets("sheet1").Cells(counter, resultColume) = price
counter = counter + 1
End If
End If
Next
myFun = counter
End Function
先按照包装、销售、拍照三项进行小计,然后计算总工资。(注:员工姓名一栏应该是可以唯一标示身份的ID)
宏代码如下:
Const N As Integer = 7
Sub calculate()
Dim counter As Integer
Dim flag As Boolean
counter = 2
Worksheets("sheet1").Cells(1, N) = "姓名"
Worksheets("sheet1").Cells(1, N + 1) = "包装工资"
counter = myFun(counter, 5, 2, N + 1)
Worksheets("sheet1").Cells(1, N + 2) = "销售工资"
counter = myFun(counter, 8, 3, N + 2)
Worksheets("sheet1").Cells(1, N + 3) = "拍照工资"
counter = myFun(counter, 5, 4, N + 3)
Worksheets("sheet1").Cells(1, N + 4) = "总工资"
For Index = 2 To counter - 1
With Worksheets("sheet1")
.Cells(Index, N + 4).Value = .Cells(Index, N + 1).Value + .Cells(Index, N + 2).Value + .Cells(Index, N + 3).Value
End With
Next
End Sub
Function myFun(ByVal counter As Integer, ByVal price As Integer, ByVal col As Integer, resultColume As Integer) As Integer
Dim i, k As Integer
Dim Name As String
Dim flag As Boolean
For i = 2 To Worksheets("sheet1").UsedRange.Rows.Count Step 1
Name = Worksheets("sheet1").Cells(i, col).Value
If Len(Name) > 1 Then
flag = False
For k = 2 To counter
If Name = Worksheets("sheet1").Cells(k, N).Value Then
Worksheets("sheet1").Cells(k, resultColume).Value = Worksheets("sheet1").Cells(k, resultColume).Value + price '价格为price
flag = True
Exit For
End If
Next
If flag = False Then
Worksheets("sheet1").Cells(counter, N) = Name
Worksheets("sheet1").Cells(counter, resultColume) = price
counter = counter + 1
End If
End If
Next
myFun = counter
End Function