我试图在某些条件下在另一行基础下方插入一行。现在这段代码将遍历许多工作表。它适用于 1 张纸,但是当它尝试为下一张纸执行相同的功能时,它显示错误。任何人都可以帮我解决这个问题。我使用的代码如下:
Sub test()
Dim a As Worksheet
Dim lngRow As Long
Dim s As String
Dim z As Variant
s = "Sheet1,Sheet2"
z = VBA.Split(s, ",")
For Each i In z
Set a = Sheets(i)
For lngRow = a.UsedRange.Rows.Count To 1 Step -1
If UCase$(a.Cells(lngRow, 2).Value) = "R" Then
a.Range("A" & CStr(lngRow + 1)).Select
Selection.EntireRow.Insert , CopyOrigin:=xlFormatFromLeftOrAbove
End If
Next lngRow
Next i
End Sub
错误出现在这一行:
a.Range("A" & CStr(lngRow + 1)).Select