首页 文章

Excel:在列中搜索另一个工作表上的表中的单词,如果找到任何表,则从当前单元格中的单元格中插入值

提问于
浏览
1

香港专业教育学院一直试图找到一个宏,它将逐行查看一列(工作栏a),并在另一张纸上搜索表格中的任何单词(列表a) . 如果它找到任何这些单词,它将返回下一列(列表b)中的值并将其放入工作表(工作列c)中的单元格中,并逐行向下工作表单行执行此操作 .

用宏可以实现吗?我知道if else else公式被列为7个项目,并且我正在使用更长的那个列表(并且正在增长)

1 回答

  • 0

    在所有工作表中替换范围中定义的所有表达式的示例:

    Sub ReplaceMulti()
      Dim dictionary As Range, sh As Worksheet, data(), r&, search$, replace$
    
      ' Loads a translation table from a worksheet
      ' The first column is the searched string and the second is the replacement
      Set dictionary = [Sheet1!A1:B10]
      data = dictionary.value
    
      ' iterate each sheet
      For Each sh In ActiveWorkbook.Worksheets
    
        ' skip the sheet with the dictionary
        If sh.CodeName <> dictionary.Worksheet.CodeName Then
    
          ' iterate each expression
          For r = 1 To UBound(data)
    
            If Not IsEmpty(data(r, 1)) Then
              search = data(r, 1)
              replace = data(r, 2)
    
              ' replace in the sheet
              sh.Cells.replace What:=search, replacement:=replace, _
                LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
                SearchFormat:=False, ReplaceFormat:=False
    
            End If
          Next
        End If
      Next
    End Sub
    

相关问题