0

我有一个代码可以在 B 列中查找单词“it”。然后,如果代码找到它,它会将其右侧的单元格复制到另一个工作表。有谁知道如何修改它,使其读取 B 列中的第二个“它”,而不是第一个?谢谢

Dim rcell As Range
Application.ScreenUpdating = False
For Each rcell In Range("B2:B" & ActiveSheet.UsedRange.Rows.count + 1)
If rcell.Value = "it" Then
    rcell.Offset(, 1).Copy Sheets("another sheet").Range("C" & Rows.count).End(3)(2)
    End If
Next rcell
Application.ScreenUpdating = True
End Sub
4

1 回答 1

0

尝试这个:

Dim rcell As Range
Application.ScreenUpdating = False
For Each rcell In Range("B2:B" & ActiveSheet.UsedRange.Rows.count + 1)
Dim place%
'find first instance of "it"
place = InStr(1,rcell.Value, "it")
If place <> 0 Then
    'if there is one, check to see if there is a second instance
    'line below may have to use place+1 instead of just place
    If InStr(place,rcell.Value, "it") <> 0 Then
        rcell.Offset(, 1).Copy Sheets("another sheet").Range("C" & Rows.count).End(3)(2)
    End If
End If
Next rcell
Application.ScreenUpdating = True
End Sub
于 2013-11-05T15:20:56.297 回答