当我在"With"语句旁边指定"Sheet1"时,它可以工作,但是我希望此代码在我的所有工作表上运行. Sub soek()昏暗搜索范围发现范围昏暗的sign12作为字符串昏暗sheetsarray作为工作表设置sheetsarray = ActiveWorkbook.Sheets(Array("sheet1","sheet2","sheet3"))sign12 ="ABC"与sheetsarray设置rSearch = .Range("A1",.Range("A"&Rows.Count).End(xlUp))设置rFound = rSearch.Find(What:= sign12,LookIn:= xlValues)如果rFound什么都没有,那么别的rFound.Offset(0,1).ClearContents万一结束于结束子 这个问题很像:如何在Excel工作簿的所有工作表中搜索字符串? 但是,我认为,比起上面链接中的代码,了解如何使代码在读取我的代码的其他工作表上运行要容易得多.解决方案尝试一下(上面评论的汇总;-) Sub soek()昏暗搜索范围发现范围昏暗的sign12作为字符串昏暗的oWB作为工作簿昏暗的oWS作为工作表设置oWB = ThisWorkbooksign12 ="ABC"对于oWB.Sheets中的每个oWS使用OWS设置rSearch = .Range("A1",.Range("A"&Rows.Count).End(xlUp))设置rFound = rSearch.Find(What:= sign12,LookIn:= xlValues)如果rFound什么都没有,那么别的rFound.Offset(0,1).ClearContents万一结束于下一个OWS结束子 I have around 30 sheets that I want this code to run in at the same time. I want to find "ABC" and delete the value of the cell next to it in all my worksheets.I get my error from: Set rSearch = .**range**("A1", .range("A" & rows.count).end(x1up))When I have specified "Sheet1" next to the "With" statement, it works, but I want this code to run on all my sheets.Sub soek() Dim rSearch As Range Dim rFound As Range Dim sign12 As String Dim sheetsarray As Sheets Set sheetsarray = ActiveWorkbook.Sheets(Array("sheet1", "sheet2", "sheet3")) sign12 = "ABC" With sheetsarray Set rSearch = .Range("A1", .Range("A" & Rows.Count).End(xlUp)) Set rFound = rSearch.Find(What:=sign12, LookIn:=xlValues) If rFound Is Nothing Then Else rFound.Offset(0, 1).ClearContents End If End WithEnd SubThis question is a lot like: How to search for a string in all sheets of an Excel workbook?But in my opinion, it's a lot easier to understand how to make code run on additional sheets reading my code than the code from the link above. 解决方案 Try this (compilation of the comments above ;-)Sub soek()Dim rSearch As RangeDim rFound As RangeDim sign12 As StringDim oWB As WorkbookDim oWS As WorksheetSet oWB = ThisWorkbooksign12 = "ABC"For Each oWS In oWB.SheetsWith oWS Set rSearch = .Range("A1", .Range("A" & Rows.Count).End(xlUp)) Set rFound = rSearch.Find(What:=sign12, LookIn:=xlValues) If rFound Is Nothing Then Else rFound.Offset(0, 1).ClearContents End IfEnd WithNext oWSEnd Sub 这篇关于如何在多个Wksheets中同时搜索字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-25 10:05