在VBA for Excel中,如何将以下代码限制为仅在一个选项卡中运行?

在VBA for Excel中,如何将以下代码限制为仅在一个选项卡中运行?,excel,vba,Excel,Vba,我正在使用以下Excel VBA脚本: Sub Multi_FindReplace() 'PURPOSE: Find & Replace a list of text/values throughout entire workbook 'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault Dim sht As Worksheet Dim fndList As Variant Dim rplcList As Variant Dim x As

我正在使用以下Excel VBA脚本:

Sub Multi_FindReplace()
'PURPOSE: Find & Replace a list of text/values throughout entire workbook
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault

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

fndList = Array("Mostly satisfied", "Completely satisfied", "N/A", "Not at all satisfied")
rplcList = Array("Satisfied", "Satisfied", "Satisfied", "Not satisfied")


'Loop through each item in Array lists
  For x = LBound(fndList) To UBound(fndList)
    'Loop through each worksheet in ActiveWorkbook
      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
但问题是,它在我工作表的所有3个选项卡上运行,而我只想让它在一个单独的选项卡上运行—称为“优化”

如何更改代码,使其仅在“优化”选项卡上循环

我是否需要删除行Dim sht As工作表并将其设置为:

将sht调暗为精加工1?

更换:

'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)

    'Loop through each worksheet in ActiveWorkbook
    For Each sht In ActiveWorkbook.Worksheets '<-- This line is looping through worksheets
        sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
        LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
        SearchFormat:=False, ReplaceFormat:=False
    Next sht

Next x

删除For Each循环并添加set sht=ActiveWorkbook.SheetsRefined1.@PeterT-好的,我会试试,谢谢!有人会认为“在ActiveWorkbook中循环查看每个工作表已经足够清楚了……”@PeterT-为什么它是精化的1而不仅仅是精化的?我从OP的底部选择了“精化的1”。它可以是任意一种方式,但应该与他的工作表名相匹配。
Set sht = ActiveWorkbook.Sheets("Refined1")

'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)

    sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
    SearchFormat:=False, ReplaceFormat:=False

Next x