我在让循环在 Excel VBA 中工作时遇到了一些麻烦,该循环在每一行中的单元格 E 中搜索一个字符串,然后将该字符串放入该行的单元格 N 中。代码如下:
Dim i As Long
For i = 1 To Rows.Count
Next i
If Cells(i, 5).InStr(1, ActiveSheet.Range("ActiveCell").Value, "Smith") > 0 Then
Cells(i, 14).ActiveCell = "Smith"
End If
谁能告诉我我哪里出错了?
最佳答案
尝试:
Dim i As Long
For i = 1 To Rows.Count
If Cells(i, 5).InStr(1, ActiveSheet.Range("ActiveCell").Value, "Smith") > 0 Then
Cells(i, 14).ActiveCell = "Smith"
End If
Next i
你甚至在它做任何事情之前就结束了你的循环。
我想你也需要更换
Cells(i, 14).ActiveCell = "Smith"
和
Cells(i, 14).Value = "Smith"
关于vba - 在 VBA 中循环字符串的看似简单的任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25250000/