0
我有3個帶有不同數據的工作表的Workbook。現在我試圖爲每個工作表執行相同的代碼(用1,3列的數據連接特定的單詞,然後將3個單元格的範圍從行轉移到列) 下面的代碼實際上並不需要我需要。簡單地爲最後一張紙做正確的處理,然後將這個結果複製到另一張紙上。但我需要每張紙的獨特結果。 任何幫助,非常感謝!針對每個工作表循環的Excel VBA(在多個表格上運行相同的VBA宏代碼)
Option Explicit
Sub forEachWS()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.Columns("G:J").Clear
Call execute(ws)
Next
End Sub
Sub execute(ws As Worksheet)
Dim intLastRow As Long
Dim intR As Long
Const intStartRow As Integer = 2
Dim destRow As Long
With ws
intLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
destRow = 2
For intR = intStartRow To intLastRow
.Range("G" & intR) = "ID =" & Cells(intR, 1).Value
.Range("H" & intR) = "[FROM].[#" & Cells(intR, 3).Value
.Range("I" & intR) = "END"
.Range("G" & intR & ":I" & intR).Copy
.Range("J" & destRow).PasteSpecial Transpose:=True
destRow = destRow + 3
Next
End With
End Sub