我在Sheet2的“ A”列中有一个子字符串,该字符串是使用LEFT函数获取的。每次导入时,情况都在变化,我试图在Sheet1的“ AI”列中找到它。然后,我想将Sheet1中的列从“ AI”复制到“ AF”并将其粘贴到Sheet2中。我在做什么错了?
Sub InStrDemo()
Dim lastrow As Long
Dim i As Integer, icount As Integer
Dim LResult As String
LResult = Sheets("Sheet2").Range("A2")
LResult = Left(LResult, 4)
lastrow = Sheets("Sheet1").Range("A30000").End(xlUp).Row
icount = 1
For i = 2 To lastrow
If InStr(1, LCase(Range("AI" & i)), LCase(LResult)) <> 0 Then
icount = icount + 1
Sheets("Sheet2").Range("B" & icount & ":E" & icount) =
Sheets("Sheet1").Range("AF" & i & ":AI" & i).Value
End If
Next i
End Sub
答案 0 :(得分:0)
您正在尝试复制和粘贴,如果要进行比较,=后应为_。看看是否有效:
Sheets("Sheet2").Range("B" & icount & ":E" & icount) = _
Sheets("Sheet1").Range("AF" & i & ":AI" & i).Value