내 코드가 Error 9, Subscript out of range
오류를 발생시키는 경우가 있습니다. 다른 많은 것들 중에서도 내 코드는 많은 양의 셀을 필요로하고 기존의 조건부 서식을 제거한 다음범위에 방금 추가 한 항목 수에 따라 조건을 추가하여 다시 적용합니다. 난 (12) = 에러 그것은으로 일어나면 조금 랜덤 표시 Case Else, .FormatConditions(i).Font.Color = vbWhite.
에서 발생하지만, 자주 .Font.Color = vbWhite
발생했을 때에 순간 첨자가 범위를 벗어남 오류 (오류 9) : .FormatConditions
Function FormatLevelX()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim r As Integer
Dim sLevelRangeName As String
For j = 1 To Sheets("LEVEL").Range("MajorLevels").Columns.Count 'repeat this for each of the major levels
sLevelRangeName = "Level" & Sheets("LEVEL").Range("MajorLevels").Cells(1, j)
For k = 1 To Sheets("LEVEL").Range(sLevelRangeName).Columns.Count 'repeat this for each column per major level
For r = 2 To 5 'repeat this for each of the 4 cells (each on a different row) in the column that need conditional formatting
With Sheets("LEVEL").Range(sLevelRangeName).Cells(r, k)
.FormatConditions.Delete
.Validation.Delete
For i = 1 To Sheets("Level").Range("MajorLevels").Columns.Count 'make one rule per major level
.FormatConditions.Add Type:=xlExpression, Operator:=xlEqual, Formula1:="=MATCH(" & ColLett(Range(sLevelRangeName).Cells(2, k).Column) & "2,MajorLevels,0)=" & i
Select Case (i)
Case 1, 2, 3, 4, 5
.FormatConditions(i).Interior.ColorIndex = 45 + i
.FormatConditions(i).Font.Color = vbWhite
.FormatConditions(i).NumberFormat = "@"
Case 6
.FormatConditions(i).Interior.ColorIndex = 23
.FormatConditions(i).Font.Color = vbWhite
.FormatConditions(i).NumberFormat = "@"
Case 7, 8, 9
.FormatConditions(i).Interior.ColorIndex = 45 + i + 1
.FormatConditions(i).Font.Color = vbWhite
.FormatConditions(i).NumberFormat = "@"
Case Else
.FormatConditions(i).Interior.ColorIndex = 9 + i - 10
.FormatConditions(i).Font.Color = vbWhite
.FormatConditions(i).NumberFormat = "@"
End Select
Next i
End With
Next r
Next k
Next j
End Function
는 오류를 초래한다. 간단히 말해서 REM을 사용하면 가끔씩 사라집니다 (분명히 솔루션이 아닙니다!). 그러나 형식 조건이 추가 된 다른 행 중 하나에 나타납니다.
도움을 주시면 대단히 감사하겠습니다.
+1 귀하의 문제를 설명하는 동안 모든 세부 사항을 다루는 :) 나는 당신이 오류 메시지와 당신이 가리키는 라인과 혼란스러워하고 왜 이것이 일어날 수도 있다고 생각합니다. Excel에서 특정 개체를 찾을 수없는 경우 아래 첨자 범위를 벗어난 오류가 발생합니다. 예를 들어'FormatConditions (12)'는'vbWhite' 때문에 발생하지 않습니다 –
''런타임 오류 '가 더 많을 것입니다 1004 :'해당 응용 프로그램 정의 또는 객체 정의 오류 '오류 ... –
A 어둠에 쐈어. 나 한테 뭔가 해줄 수있어? '.Font.Color = vbWhite'를'.Font.ColorIndex = 2'로 변경 하시겠습니까? –