|
楼主 |
发表于 2024-11-19 21:09
|
显示全部楼层
现有代码插入行可以自动复制公式,列如何写不会了
Sub Worksheet_Change(ByVal Target As Range)
Dim i, hy, px, hj As Integer
If Target.Columns.Count = Columns.Count And Application.CountA(Target) = 0 Then
For i = 2 To Columns.Count '获取列数
If Cells(2, i) = "差旅费" Then
cl = i '获取列数
Cells(Target.Row, cl).FormulaR1C1 = Cells(Target.Row - 1, cl).FormulaR1C1
End If
If Cells(2, i) = "会议费" Then
hy = i '获取列数
Cells(Target.Row, hy).FormulaR1C1 = Cells(Target.Row - 1, hy).FormulaR1C1
End If
If Cells(2, i) = "培训费" Then
px = i '获取列数
Cells(Target.Row, px).FormulaR1C1 = Cells(Target.Row - 1, px).FormulaR1C1
End If
If Cells(2, i) = "合计" Then
hj = i '获取列数
Cells(Target.Row, hj).FormulaR1C1 = Cells(Target.Row - 1, hj).FormulaR1C1
End If
Next i
On Error Resume Next
Target(1).Offset(, 3).Resize(Target.rows.Count, ActiveSheet.UsedRange.Columns.Count).SpecialCells(xlCellTypeConstants, 1) = ""
End If
end Sub |
|