Vba 如何在excel中循环浏览预定义工作表列表?

Vba 如何在excel中循环浏览预定义工作表列表?,vba,excel,Vba,Excel,所以我通过尝试、错误和搜索来学习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) = R

所以我通过尝试、错误和搜索来学习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循环放在通过ReportA到ReportZ循环的内容中,而不是为每个报告复制此代码块?

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

这可以通过引用其他地方的列表来完成吗?如果报告不再命名为“ReportA”,而是“ReportJohn”、“ReportDave”等,我不确定这两个嵌套的报告的顺序是否正确。。。下一个循环;您可能希望将
i
循环放在
a
循环中。然后您将构建一个工作表名称数组并循环它们。它们是工作簿中唯一的工作表吗?如果每个工作表都需要进行该计算,您可以使用
For…For…Each
代码块浏览文件中的所有工作表。您可以使用区块内的
选择案例
忽略某些表格。请将完整代码分享给我们好吗?