|
楼主 |
发表于 2023-3-16 21:22
|
显示全部楼层
最终摸索了实现了如下代码,以后还需向各位大佬多学习学习
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Private Sub Worksheet_UpdateData()
Dim lastRow As Long
Dim i As Long
lastRow = Cells(Rows.Count, "A").End(xlUp).Row '获取最后一行
For i = 1 To lastRow '循环遍历每一行
If InStr(Cells(i, "A").Value, "数据") > 0 Then '如果A列包含“数据”
Cells(i, "H").Value = 30# '将H列赋值为30.00
Cells(i, "I").Value = Cells(i, "G").Value * Cells(i, "H").Value '将G列和H列的乘积放于I列
Cells(i, "N").Value = 40# '将H列赋值为40.00
Cells(i, "O").Value = Cells(i, "M").Value * Cells(i, "N").Value '将G列和H列的乘积放于I列
Cells(i, "T").Value = 40# '将H列赋值为40.00
Cells(i, "U").Value = Cells(i, "S").Value * Cells(i, "T").Value '将G列和H列的乘积放于I列
Cells(i, "Z").Value = 40# '将H列赋值为40.00
Cells(i, "AA").Value = Cells(i, "Y").Value * Cells(i, "Z").Value '将G列和H列的乘积放于I列
Cells(i, "AC").Value = Cells(i, "I").Value + Cells(i, "O").Value + Cells(i, "U").Value + Cells(i, "AA").Value '将I列、O列、U列和AA列的和放于AC列
Cells(i, "AB").Value = Cells(i, "G").Value + Cells(i, "M").Value + Cells(i, "S").Value + Cells(i, "Y").Value
End If
If InStr(Cells(i, "A").Value, "班组") > 0 Then '如果A列包含“班组”
Cells(i, "D").Value = "日期" '将D列赋值为日期
Cells(i, "E").Value = "时间" '将E列赋值为时间
Cells(i, "F").Value = "事由" '将F列赋值为事由
Cells(i, "G").Value = "天数" '将G列赋值为天数
Cells(i, "H").Value = "报销标准" '将H列赋值为报销标准
Cells(i, "I").Value = "金额" '将I列赋值为金额
Cells(i, "J").Value = "日期" '将D列赋值为日期
Cells(i, "K").Value = "时间" '将E列赋值为时间
Cells(i, "L").Value = "事由" '将F列赋值为事由
Cells(i, "M").Value = "天数" '将G列赋值为天数
Cells(i, "N").Value = "报销标准" '将H列赋值为报销标准
Cells(i, "O").Value = "金额" '将I列赋值为金额
Cells(i, "P").Value = "日期" '将D列赋值为日期
Cells(i, "Q").Value = "时间" '将E列赋值为时间
Cells(i, "R").Value = "事由" '将F列赋值为事由
Cells(i, "S").Value = "天数" '将G列赋值为天数
Cells(i, "T").Value = "报销标准" '将H列赋值为报销标准
Cells(i, "U").Value = "金额" '将I列赋值为金额
Cells(i, "V").Value = "日期" '将D列赋值为日期
Cells(i, "W").Value = "时间" '将E列赋值为时间
Cells(i, "X").Value = "事由" '将F列赋值为事由
Cells(i, "Y").Value = "天数" '将G列赋值为天数
Cells(i, "Z").Value = "报销标准" '将H列赋值为报销标准
Cells(i, "AA").Value = "金额" '将I列赋值为金额
End If
Next i
End Sub
|
|