VBA find/replace using array for cell range

女生的网名这么多〃 提交于 2021-02-08 08:25:56

问题


I receive a quarterly data set where I need to make some general changes to the data. The changes are routinely the same and I want to use a macro to change them in one fell swoop rather than find/replace manually. I found a script that saves my data as an array and then searches the entire workbook. It works BUT I only want it to find/replace in a specific range. I've tried many times to alter the code, but I am unable to. I don't even know if this is the best way to accomplish it - very open to all feedback!

Sub Multi_FindReplace()

Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long

fndList = Array("Unnamed Rd", "526-566 Stanford UniversityLagunita Dr", "Social Science Parking Structure")
rplcList = Array("Departure Access Rd", "526-566 Lagunita Dr", "4139 Campus Dr")

  For x = LBound(fndList) To UBound(fndList)
  For Each sht In ActiveWorkbook.Worksheets
    sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
      LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
      SearchFormat:=False, ReplaceFormat:=False
  Next sht

  Next x

End Sub

来源:https://stackoverflow.com/questions/41291498/vba-find-replace-using-array-for-cell-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!