如何在不知道工作表的确切数量的情况下 select 来自所有工作表的特定单元格?

How do I select specific cells from ALL worksheets without knowing the exact number of worksheets?

我完全是个初学者。这是我的部分代码:

Workbooks("xxx").Worksheets(1).Activate
Range("A1").Select
Selection.Copy

Workbooks("yyy").Worksheets(1).Activate
Range("B2").Select
ActiveSheet.Paste

Workbooks("xxx").Worksheets(2).Activate
Range("A2").Select
Selection.Copy

Workbooks("yyy").Worksheets(1).Activate
Range("B3").Select
ActiveSheet.Paste

每个 xxx 工作簿包含未知数量的工作表。它可以是 3,也可以是 50。如果我手动复制并粘贴上面的代码,例如。 50 次,如果工作表的数量等于 30,宏将显示错误并停止。我怎样才能使它自动化?请记住,我是新手,所以请保持简单的回答。

试试下面的代码。

Dim wbX As Workbook
Dim wbY As Workbook
Set wbX = Application.Workbooks("xxx")
Set wbY = Application.Workbooks("yyy")

For i = 1 To wbX.Sheets.Count
  wbX.Sheets(i).Activate
  Range("A" & i).Select
  Selection.Copy

  wbY.Sheets(1).Activate
  Range("B" & i + 1).Select
  ActiveSheet.Paste
Next

湿婆回答。谢谢!

Dim wbX As Workbook
Dim wbY As Workbook
Set wbX = Application.Workbooks("xxx")
Set wbY = Application.Workbooks("yyy")

For i = 1 To wbX.Sheets.Count
wbX.Sheets(i).Activate
Range("A1").Select
Selection.Copy

wbY.Sheets(1).Activate
Range("B" & i + 1).Select
ActiveSheet.Paste
Next