Excel填充数据

我有以下input数据:

在这里输入图像说明

我需要用不同的支付率和期限填充每行3行,如下所示:

在这里输入图像说明

该委员会的支付基于以下费率:
我)第一个月 – 50%
ii)第二个月 – 30%
iii)第三个月 – 20%

例:-

在这里输入图像说明

下一个标准是佣金支付期。 当月收款将在接下来的几个月内支付。

我如何使用Excel和macros来做到这一点?

谢谢。

假设您的数据位于第一张纸上,请创build第二张纸并运行此macros:

Option Explicit Sub popData() Dim r As Integer, r2 As Integer, p As Integer: r2 = 3 Dim sht2 As Worksheet: Set sht2 = Sheets(2) Dim rate(), headings() rate = Array(0.5, 0.3, 0.2) headings = Array("Date", "Sales", "Commission", "Collection Date", "Invoice No") For r = 0 To UBound(headings): sht2.Cells(2, r + 1).Value = headings(r) Next Dim dat As Date With Sheets(1) sht2.Cells(1, 1).Value = "Payout" For r = 3 To .Cells(.Rows.Count, "A").End(xlUp).row: For p = 0 To 2: sht2.Cells(r2, "A").NumberFormat = .Cells(r, "A").NumberFormat dat = DateAdd("m", p + 1, CDate(.Cells(r, "A"))) sht2.Cells(r2, "A").Value = DateSerial(year(dat), month(dat) + 1, 0) sht2.Cells(r2, "B").Value = .Cells(r, "B").Value sht2.Cells(r2, "C").NumberFormat = "0.00" sht2.Cells(r2, "C").Value = .Cells(r, "C").Value * rate(p) sht2.Cells(r2, "D").NumberFormat = .Cells(r, "A").NumberFormat sht2.Cells(r2, "D").Value = .Cells(r, "A").Value sht2.Cells(r2, "E").Value = .Cells(r, "D").Value r2 = r2 + 1 Next Next End With sht2.Columns("A:E").EntireColumn.AutoFit End Sub 

第一个循环将标题添加到第二个工作表。 下一个双循环通过内循环处理每个销售人员为每个佣金支出创build3行。 看起来你想要下个月的最后一天 – 通过在当前date中添加一个月然后使用DateSerial函数来查找那个月份的最后一天。 最后一行只是确保所有列都扩展到最大的文本input,所以一切都可见。