EXCEL中利用VB判断正确后插入一列

2025-02-24 00:24:22
推荐回答(3个)
回答1:

你到底是要插入行还是插入列?
判定的位置插入列:

Sub abc2()

For i = 1 To 10
t = Cells(i, 1).Value
If t = 5 Then
'插入列在前
Cells(i, 1).EntireColumn.Insert
'插入列在后
' Cells(i, 2).EntireColumn.Insert
End If
Next

End Sub

回答2:

Sub abc2()
For i = 1 To 100
t = Cells(i, 1).Value
If t = 5 Then
Rows(i + 1).Insert
End If
Next
End Sub

回答3:

Sub abc2()
For i = 1 To 100
t = Cells(i, 1).Value
If t = 5 Then
Selection.EntireRow.Insert
End If
Next
End Sub