以下程式碼,目前小弟是以迴圈方式設計,當資料大時跑的速度有點久,不知有其有辦法再簡化或其他方式執行??
sub aa()
Dim sht As Worksheet
For mon = 1 To 12
Application.EnableEvents = False
For Each sht In Worksheets
col = Sheets(mon & "月未結").Range("A1").End(xlToRight).Column
r = Sheets(mon & "月未結").Range("AA1").Value
For x = 7 To col
For y = 2 To r
mony = Application.IfError(Application.VLookup(Sheets(mon & "月未結").Range("A" & y), Sheets("" & sht.Name).Range("A:U"), Application.Match(Sheets("" & sht.Name).Cells(1, x),
Sheets("" & sht.Name).Range("A1:U1"), 0), 0), "")
Sheets(mon & "月未結").Cells(y, x) = mony
Next
Next
End If
Next
Application.EnableEvents = True
Next mon
end sub |