VBA查找特定单词并将值复制到另一个单元格

时间:2018-11-07 15:21:16

标签: excel vba excel-vba excel-2013

我正在寻找有关vba的帮助。

我想在A列中搜索“ CAMBUSLANG的摘要”,如果找到了,则将D列中的值分配给另一个单元格以进行讨论,例如说另一个电子表格的A列。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

使用Range.Find Method在A列中找到您的特定字符串,并使用Range.Offset Property移至D列:

Option Explicit

Public Sub Example()
    Dim FoundAt As Range
    Set FoundAt = Worksheets("SearchSheet").Columns("A").Find(What:="Summary of CAMBUSLANG", LookIn:=xlValues, LookAt:=xlWhole)

    If Not FoundAt Is Nothing Then 
        Worksheets("AnotherSheet").Range("A1").Value = FoundAt.Offset(ColumnOffset:=3).Value
    Else 'nothing found
        MsgBox "'Summary of CAMBUSLANG' not found.", vbCritical
    End If
End Sub
相关问题