0
我正在研究一些VBA,旨在循環使用Excel製作的學生的Schedule Builder。在作業c = c.Offset(X, 0)
期間,我一直收到錯誤424,但只在嵌套的For循環中出現。有限的範圍,如果是的話,我如何克服它?for循環中的單元格對象的作用域 - VBA
下面是代碼:
Public Sub generateRosters()
Worksheets("Course Rosters").Cells.ClearContents
Worksheets("Course Rosters").Range("A1") = "Course"
Worksheets("Course Rosters").Range("B1") = "Room"
Dim classTitleRange As Range
Set classTitleRange = Worksheets("Master School Schedule").Range("D1:BN1")
Dim rowCount As Integer
rowCount = 2
Dim periodArr(1 To 8) As String
periodArr(1) = "A"
periodArr(2) = "B"
periodArr(3) = "C"
periodArr(4) = "D"
periodArr(5) = "E"
periodArr(6) = "F"
periodArr(7) = "G"
periodArr(8) = "Z"
For Each c In classTitleRange.Cells
Dim courseTitle As String
courseTitle = c
c = c.Offset(2, 0)
Dim room As String
room = c
For Each p In periodArr()
Dim offsetCount As Integer
offsetCount = 0
For i = 1 To 340
c = c.Offset(1, 0) '424 Error One
If c = p Then
End If
offsetCount = offsetCount + 1
Next
c = c.Offset(-offsetCount, 0) '424 Error Two
Next
Worksheets("Course Rosters").Range("A" & rowCount) = "'" & courseTitle
Worksheets("Course Rosters").Range("B" & rowCount) = room
rowCount = rowCount + 1
Next
End Sub
謝謝您的幫助。
編輯:旁邊的問題,有沒有辦法讓我創建一個變量,我可以像c一樣操作,但不是c。基本上是Dim d As (Something)
,然後是d = c
。我似乎無法找到指定給d的正確對象,所以我可以使它成爲c。再次感謝。
我的邏輯是,我對VBA相當陌生,並不知道更好。謝謝您的幫助! – user2004245