如何循环在Excel中预定义的工作表列表?

所以我通过试用,错误和search来学习VBA。 现在我有这样的东西:

For i = 1 To NewEntries MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(tnd, example, 0) + 1) = ReportA.Cells(2, 3).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Date, example, 0) + 1) = ReportA.Cells(2, 5).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Code, example, 0) + 1) = ReportA.Cells(4 + i, 2).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Desc, example, 0) + 1) = ReportA.Cells(4 + i, 3).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Price, example, 0) + 1) = ReportA.Cells(4 + i, 4).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Sprice, example, 0) + 1) = ReportA.Cells(4 + i, 5).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Disc, example, 0) + 1) = ReportA.Cells(4 + i, 6).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Payment, example, 0) + 1) = ReportA.Cells(4 + i, 7).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Bank, example, 0) + 1) = ReportA.Cells(4 + i, 8).Value Next 

我怎么能把FOR循环里面的东西,通过ReportZ通过ReportA而不是复制这个代码块为每个报告?

使用Chr与ascii代码。

 dim a as long For i = 1 To NewEntries for a = 65 to 90 with worksheets("report" & chr(a)) debug.print .Cells(2, 3).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(tnd, example, 0) + 1) = .Cells(2, 3).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Date, example, 0) + 1) = .Cells(2, 5).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Code, example, 0) + 1) = .Cells(4 + i, 2).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Desc, example, 0) + 1) = .Cells(4 + i, 3).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Price, example, 0) + 1) = .Cells(4 + i, 4).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Sprice, example, 0) + 1) = .Cells(4 + i, 5).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Disc, example, 0) + 1) = .Cells(4 + i, 6).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Payment, example, 0) + 1) = .Cells(4 + i, 7).Value MH.Cells(i + LastRow2, Application.WorksheetFunction.Match(Bank, example, 0) + 1) = .Cells(4 + i, 8).Value end with next a next i