2

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

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

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
4

1 回答 1

0

编辑 1:添加了更好的代码

我删除了您的 ws_loop 并将其放在循环所有工作表的新循环的中间。我还在顶部添加了一个选择以在工作表和接近末尾的 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
于 2013-06-11T13:19:20.680 回答