EXCEL2010中如何在隨意位置插入一行后,该行能自动复制上一行的所有公式及格式

excel

1个回答

写回答

锋仔2198

2025-12-27 13:21

+ 关注

excel
excel

excel宏很容易实现:;按 alt + f11,双击工程资源管理器里面的sheet1(sheet1),在右侧的代码区粘贴下面的代码。运行,就OK了。;1.在excel中,在任意位置插入一行后,该行能自动复制上一行的所有公式及格式(用VBA

Private Sub Worksheet_Change(ByVal Target As Range) a = Target.Row() b = Target.Column() Application.ScreenUpdating = False If a 1 Then If Cells(a, b) = "" And Cells(a - 1, b) "" Then For x = 1 To 256 If Cells(a - 1, x).HasFormula = True Then Cells(a - 1, x).Copy Cells(a, x).Select ActiveSheet.Paste Application.CutCopyMode = False End If Next x Cells(a, b).Select End If End If Application.ScreenUpdating = TrueEnd Sub

;2.在excel中,在任意位置插入一行后,该行能自动复制上一行(用VBA)Private Sub Worksheet_Change(ByVal Target As Range1) a = Target.Row() b = Target.Column() If a 1 Then If Cells(a, b) = "" And Cells(a - 1, b) "" Then Rows(a - 1 & ":" & a - 1).Copy Cells(a, b).Select ActiveSheet.Paste c = Cells(a, b) Application.CutCopyMode = False ActiveCell.FormulaR1C1 = c Cells(a, b).Select End If End IfEnd Sub

举报有用(0分享收藏

Copyright © 2025 IZhiDa.com All Rights Reserved.

知答 版权所有 粤ICP备2023042255号