首页 > 解决方案 > 如果为真,则搜索 B 列中的文本并将其他文本传递到 L 列

问题描述

我需要在 B:B 列中搜索特定文本,然后如果真的将其他文本粘贴到 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

如果为真,我只能粘贴第一个文本,或者用相同的文本填充 L:L 列。

标签: excelvba

解决方案


你的意思是这样的吗?

  • 如果 B 列是,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

您可能会从阅读 如何避免在 Excel VBA 中使用 Select 中受益。


推荐阅读