如何在不同的工作表上运行特定范围的macros?

我有一个macros读取范围内的一些数据,并询问是否要更改它,然后更改任何其他单元格是相同的方式。 它只能在一张纸上工作,我怎样才能改变它,以便它search所有其他纸张相同的范围?

我这样写,但我不知道为什么其他表中的其他数据不会改变

Sub standardize() For Each ws In ActiveWorkbook.Worksheets For Each Title In Range("O1:O2000").Cells Dim des As String des = Title.Value If Left(des, 1) <> "*" And Title.Value <> 0 Then Dim MyDataObj As New DataObject MyDataObj.SetText des MyDataObj.PutInClipboard newtitle = Application.InputBox(prompt:=des, Title:=" Input The description as you like!", Type:=2) If newtitle <> False Then For Each cate In ActiveWorkbook.Worksheets.Range("O1:O2000").Cells If titl.Value = des Then titl.Value = "*" & newtitle End If Next titl Next cate End If End If Next Title Next ws End Sub 

编辑1:添加更好的代码

我删除了你的ws_loop,并把它放在一个循环遍历所有工作表的中间。 我还在顶部添加了一个select,在表单和最后一个msgbox之间切换。

 Sub standardize() Dim WS_Count As Integer Dim I As Integer ' Set WS_Count equal to the number of worksheets in the active ' workbook. WS_Count = ActiveWorkbook.Worksheets.Count ' Begin the loop. For I = 1 To WS_Count ActiveWorkbook.Worksheets(I).select ''''Below is your code without the ws loop For Each Title In Range("O1:O2000").Cells Dim des As String des = Title.Value If Left(des, 1) <> "*" And Title.Value <> 0 Then Dim MyDataObj As New DataObject MyDataObj.SetText des MyDataObj.PutInClipboard newtitle = Application.InputBox(prompt:=des, Title:=" Input The description as you like!", Type:=2) If newtitle <> False Then For Each cate In ActiveWorkbook.Worksheets.Range("O1:O2000").Cells If titl.Value = des Then titl.Value = "*" & newtitle End If Next titl Next cate End If End If Next Title MsgBox ActiveWorkbook.Worksheets(I).Name Next I End Sub