我需要在B:B列中搜索特定文本,然后如果为true,则将其他文本粘贴到L:L列,例如:
Sub teste()
Application.ScreenUpdating = False
last = Cells(Rows.Count, "B").End(xlUp).Row
For i = last To 1 Step -1
If (Cells(i, "B").Value) = "string_1" Then
Range("L2").Select
ActiveCell.FormulaR1C1 = "some_text_1"
'LastRow = Range("A" & Rows.Count).End(xlUp).Row
'Range("L2").AutoFill Destination:=Range("L2:L" & LastRow)
End If
Next i
End Sub
我只能粘贴第一个文本(如果为true)或在L:L列中填充相同的文本。
答案 0 :(得分:0)
你的意思是那样的吗?
string_1
,则将C列复制到L列For i = last To 1 Step -1
If (Cells(i, "B").Value) = "string_1" Then
'copy value from C to L
Cells(i, "L").Value = Cells(i, "C").Value
End If
Next i
您可能会受益于阅读 How to avoid using Select in Excel VBA。
答案 1 :(得分:0)
Sub teste()
Application.ScreenUpdating = False
s1 = "first_text"
s2 = "second_text"
s3 = "third_text"
last = Cells(Rows.Count, "B").End(xlUp).Row
For i = last To 1 Step -1
If (Cells(i, "B").Value) = "string_1" Then
Cells(i, "L").Value = s1
ElseIf (Cells(i, "B").Value) = "String_2" Then
Cells(i, "L").Value = s2
ElseIf (Cells(i, "B").Value) = "string_3" Then
Cells(i, "L").Value = s3
End If
Next i
End Sub