각 셀에서 문자열을 배열로 분할 한 다음 추가 할 점 수를 결정한 다음 추가하여 표시합니다. 그러나 나는 그것이 여러 문장을 수정 했는데도 여전히 어떤 부분도 얻지 못했기 때문에 split 문장과 관련이 있다고 생각한 범위 밖의 첨자를 계속 사용하고있다. 나는 또한 아마 분할이 아니었고 어쩌면 그 셀에 아무것도 없었지만 (ElseIf array = ""Then) 그걸 처리 했어야한다고 생각했다. Excel VBA subscript out of range
Sub pointsAdd()
'Init Variables
Dim pointArray() As String
Dim j As Integer
Dim i As Integer
Dim points As Integer
'Make sure the correct sheet is selected
Worksheets("Sheet1").Activate
'Add Points Up
For j = 2 To 100
Cells(j, 1).Select
If ActiveCell.Value = "" Then
j = 100
Else
For i = 3 To 22
Cells(j, i).Select
pointArray = Split(ActiveCell.Value, ".")
'The next line is where the debugger says the script is out of range
If pointArray(0) = "Tardy" Then
points = 0.5
ElseIf pointArray(0) = "Failure To Complete Shift" Then
points = 0.5
ElseIf pointArray(0) = "Failure To Complete At Least Half Shift" Then
points = 0.5
ElseIf pointArray(0) = "Absence" Then
points = 1
ElseIf pointArray(0) = "Late Call Off" Then
points = 2
ElseIf pointArray(0) = "No Call/No Show" Then
points = 4
ElseIf pointArray(0) = "" Then
i = i + 1
Else
MsgBox "Somthing is wrong in Module 1 Points Adding"
End If
'Add points to points cell
Cells(j, 2).Select
points = points + ActiveCell.Value
ActiveCell.Value = points
Next i
End If
Next j
End Sub
는 또한 셀에 있어야 문자열의 형식은 "Occurrence.Description.Person.mm/dd/yyyy"입니다 : 여기에 내 코드입니다.
어떤 줄에 아래 첨자가 범위를 벗어 납니까? 해당 오류가 발생하면 디버그 단추를 클릭하십시오. 오류를 일으키는 줄이 코드에서 강조 표시됩니다. – NavkarJ
하지만 i 루프에서 빈 셀을 사용할 수도 있습니까? – SJR
'C : V' 열에있는 셀이 비어 있습니까? 그렇다면'pointArray (0)'에 접근하려고 할 때 subscript 에러가 발생할 것입니다. – YowE3K