2014-10-22 3 views
0

최근에 조건부 서식이어야하는 Range을 감지 한 코드 조각을 작성한 다음 해당 작업을 수행하는 서브 루틴을 호출합니다 . wsWorksheet로 선언VBA - 조건부 서식 : Excel 2010이 작동하지 않습니다. Excel 2013이

' Format 
For Each ws In Results.Sheets 
    Format_em_all ws.Range(ws.Cells(15, 2), ws.Cells(15 + UBound(FreqToCompare), WrittenCells)) 
Next ws 

, ResultsWorkbook 같이 FreqToCompare 비어 있다는 가능성 없음으로 배열하고 WrittenCells하지 = 0

서브 루틴 호출 정수 :

Sub Format_em_all(RangeToFormat As Range) 

    Select Case RangeToFormat.Parent.Name 

    Case "lol" 
     RangeToFormat.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=2.9" 
     RangeToFormat.FormatConditions(1).Interior.ColorIndex = 3 
     RangeToFormat.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=2.00001", Formula2:="=2.9" 
     RangeToFormat.FormatConditions(2).Font.ColorIndex = 3 

    Case "rofl" 
     RangeToFormat.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotBetween, Formula1:="=-4", Formula2:="=4" 
     RangeToFormat.FormatConditions(1).Interior.ColorIndex = 3 

    End Select 

End Sub 

Excel 2013을 사용하여 컴퓨터에서 코드를 실행했으며 모두 원활하게 진행되었습니다. 10 분 전에 동료가 와서 내 매크로가 작동하지 않는다고 말합니다 ... 우리는 Excel 2010으로 컴퓨터를 점검하는 대신에 ... 그래, 작동하지 않습니다. Case "lol" 뒤에 "런타임 오류"5 "- 잘못된 프로 시저 호출 또는 인수가있는"첫 줄에 멈추었습니다. ? RangeToFormat.Address을 시도했는데 정확한 범위 주소가 표시됩니다 ... 무엇이 잘못 되었나요?

+0

당신이 얻는 오류는 무엇입니까? '마법의 숫자'입니까? 예를 들어 xlCellValue = 1입니까? – SeanC

+1

이 범위에는 이미 조건부 형식이 있습니까? –

+1

"붙어서"는 무엇을 의미합니까? 오류에 대한 설명 또는 관찰 된 결과가 예상과 다른 점에 대한 자세한 설명을 명확히 기재하십시오 (오류가없는 경우). –

답변

0

잘 모두 악셀 리히터로 이동이 답변에 대한 신용 : 당신이 볼 수 있듯이

Sub Format_em_all(RangeToFormat As Range) 

Select Case RangeToFormat.Parent.Name 

Case "lol" 
    RangeToFormat.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:=2.9 
    RangeToFormat.FormatConditions(1).Interior.ColorIndex = 3 
    RangeToFormat.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:=2.00001, Formula2:=2.9 
    RangeToFormat.FormatConditions(2).Font.ColorIndex = 3 

Case "rofl" 
    RangeToFormat.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotBetween, Formula1:=-4, Formula2:=4 
    RangeToFormat.FormatConditions(1).Interior.ColorIndex = 3 

End Select 

End Sub 

, 공식이 공식은 더 이상하지만, 정수하지 않습니다! 그게 완벽하게 작동