
excel
VBASub InsertRow()' 定义变量Dim ws As WorksheetDim lastRow As LongDim condition As Boolean' 设置工作表对象Set ws = ActiveSheet' 设置最后一个行数lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row' 循环判断条件并插入行For i = 1 To lastRowcondition = TrueIf i = 1 Thencondition = FalseElseIf ws(i, 3) > vbHashValue Thencondition = FalseEnd IfEnd IfIf condition = True Thenws(i, 0).End(xlUp).Offset(1, 0).CopyActiveCell.Paste Special xlPasteAll, , 1End IfNextEnd Sub以上代码将根据单元格3中的值判断是否需要插入新的行,并在需要时自动插入。请注意,在运行VBA之前,确保已经激活了开发工具,并且在循环中使用了正确的工作表对象。希望对您有所帮助!Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号