我正在编写一个从一个工作簿中提取数据并将其放入另一个工作簿的宏。我想我的代码非常正确,除了我在其中一个循环中出现的错误:
“运行时错误9:下标超出范围”
以下是代码:
Sub PullFromRunsheetsTest2()
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim file As Variant, a As String, columnItertor As Integer, path As String
path = "C:\Users\msala\Desktop\Runsheets\"
file = Dir(path & "Runsheet*")
Do Until file = "" ''looking at the first file and loops until the last one
columnIterator = 0 ''setting this as the first set of 8 numbers - will shift the next set of numbers down 8 so they don't overwrite themselves
rowIterator = 0
Do Until rowIterator = 7
a = Workbooks(file).Worksheets("Pacman Runsheet").Cells(7, (2 + rowIterator)).Value '' Set "a" = whatever value is in B7, and iterate through that row
''^^^^(THIS IS WHERE I'M GETTING THE ERROR)
ActiveSheet.Cells(5 + rowIterator + columnIterator * 8, 1).Value = a ''take that value and put it in this column, iterate through.
rowIterator = rowIterator + 1
Loop
columnIterator = columnIterator + 1 ''(ignore this for now)
file = Dir()
Loop
End Sub
从我看过的内容看来,a
的数据类型似乎存在某种问题?不完全确定那可能是什么。我是否在某处意外声明a
为array
?