编辑macros以适应所有工作表VBA

我目前有这个查询,查找“)”,并将其向下移动,直到它不是旁边的任何数据。

Sub SeekParen() Dim c As Range, wheree As Range Dim whatt As String Dim TotalCycle As Long, CounterCycle As Long whatt = ")" Set c = Range("A1:A10") Set wheree = c.Find(what:=whatt, after:=c(1)).Offset(0, 1) TotalCycle = Application.WorksheetFunction.CountIf(c, whatt) For CounterCycle = 1 To TotalCycle If wheree.Value <> "" Then Range("A2").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Set wheree = c.Find(what:=whatt, after:=c(wheree.Row)).Offset(0, 1) Else Exit For End If Next CounterCycle End Sub 

我也有一个主查询,通过所有的工作表运行每个查询。

 Sub MasterTransformationMacro() 'Dim wb As Workbook 'Set wb = Workbooks("Book2.xlsm") Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets Call SeekParen(ws) Call SeekParen(ws) Call Move(ws) Call DoTrim(ws) Call CopyA(ws) Call ReplaceDelimit(ws) Call Split(ws) Call DeleteAllEmptyCRows(ws) Call DeleteC(ws) Call Formuoli(ws) Call InsertSystemPath(ws) Next End Sub 

我只是不知道如何编辑SeekParen来适应MasterMacro。 任何帮助,将不胜感激。

如果您将工作表引用传递给函数,就像这样

 Call SeekParen(ws) 

并修改SeekParen来接收它,像这样

 Sub SeekParen(ws as Worksheet) 

那么你应该能够将传递的工作表引用附加到SeekParen正文中的每个相关行

 Dim c As Range, wheree As Range Dim whatt As String Dim TotalCycle As Long, CounterCycle As Long whatt = ")" Set c = ws.Range("A1:A10") Set wheree = c.Find(what:=whatt, after:=c(1)).Offset(0, 1) TotalCycle = Application.WorksheetFunction.CountIf(c, whatt) For CounterCycle = 1 To TotalCycle If wheree.Value <> "" Then ws.Range("A2").Select Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove Set wheree = c.Find(what:=whatt, after:=c(wheree.Row)).Offset(0, 1) Else Exit For End If Next CounterCycle