可以用VBA解决。以下是代码: 在表1中,把A2:A12命名为shijian,把B2:B12命名为minchen, 把C2:C12命名为yuanfei,把D2:D12命名为hebin 在表1上,画一按钮,把hong()指定给它。使用时点此按钮,就可执行宏了。 Sub hong() Dim MyCount As Integer Worksheets(1).Activate Range("hebin").Select With Selection .MergeCells = False Selection.ClearContents End With Range("d2").Select MyCount = 1 Do Until MyCount = 0 Selection.FormulaArray = "=SUM(IF(shijian=RC[-3],IF(xinmin=RC[-2],1,0)))" MyCount = Selection.Value If MyCount > 1 Then Selection.FormulaArray = "=SUM(IF((shijian=RC[-3])*(xinmin=RC[-2]),yuanfei,0))" Selection.Offset(0, 0).Resize(MyCount).Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With Selection.Merge Else Selection.FormulaArray = "=SUM(IF((shijian=RC[-3])*(xinmin=RC[-2]),yuanfei,0))" End If Selection.Offset(1, 0).Select Loop Selection.Offset(-1, 0).Select Selection.Clear tongcen End Sub
Sub tongcen() Dim MyCount As Integer Worksheets(1).Activate Range("e2").Select MyCount = 1 Do Until MyCount = 0 Selection.FormulaArray = "=SUM(IF(shijian=RC[-4],IF(xinmin=RC[-3],1,0)))" MyCount = Selection.Value For x = 1 To MyCount If x > 1 Then Selection.Formula = 25 Selection.Offset(1, 0).Select Else Selection.Formula = 0 Selection.Offset(1, 0).Select End If Next Loop Selection.Clear End Sub
|