Vba 关于For循环的问题
为什么这不起作用?基本上,我在一个单元格中有一个列表,我想通过将字符串复制到不同的列中来拆分以“sec”结尾的字符串和不以“sec”结尾的字符串Vba 关于For循环的问题,vba,excel,for-loop,offset,Vba,Excel,For Loop,Offset,为什么这不起作用?基本上,我在一个单元格中有一个列表,我想通过将字符串复制到不同的列中来拆分以“sec”结尾的字符串和不以“sec”结尾的字符串 Sub test_if() For i = 1 To 300 Cells(i, 2).Select If Right(Cells(i, 2), 3) = "SEC" Then ActiveCell.Select Selection.Copy Cells(i, 3).Se
Sub test_if()
For i = 1 To 300
Cells(i, 2).Select
If Right(Cells(i, 2), 3) = "SEC" Then
ActiveCell.Select
Selection.Copy
Cells(i, 3).Select
ActiveSheet.Paste
End If
If Right(Cells(i, 2), 3) <> "SEC" Then
ActiveCell.Select
Selection.Copy
'Cells(i, 4).Select
ActiveCell.Offset(i - 1, 2).Select
ActiveSheet.Paste
End If
Next i
Cells(1, 1).Select
End Sub
子测试_if()
对于i=1到300
单元格(i,2)。选择
如果正确(单元格(i,2),3)=“秒”,则
ActiveCell。选择
选择,复制
单元格(i,3)。选择
活动表。粘贴
如果结束
如果正确(单元格(i,2),3)“秒”,则
ActiveCell。选择
选择,复制
'单元格(i,4)。选择
偏移量(i-1,2)。选择
活动表。粘贴
如果结束
接下来我
单元格(1,1)。选择
端接头
试试这个:
Sub test_if()
Dim i As Integer
For i = 1 To 300
With Cells(i, 2)
If UCase(Right(.Value, 3)) = "SEC" Then
.Offset(, 1).Value = .Value
Else
.Offset(i - 1, 2).Value = .Value
End If
End With
Next i
End Sub
请读一读