VBA - Conditional formatting: Excel 2010 won't work, Excel 2013 will

Noldor130884

I recently wrote a piece of code that detects (but doesn't select) a Range which must be conditional formatted and then calls a subroutine that does the job.

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

Where ws is declared as Worksheet, Results as Workbook, FreqToCompare is an array with no possibility of being empty and WrittenCellsis an Integer not = 0.

The Subroutine called:

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

I executed the code on my computer with Excel 2013 and all went smooth. 10 mins ago comes a colleague and says that my macro doesn't work... we go togheter to check on his computer with Excel 2010... and yeah, it doesn't work. It gets stuck at the first line after Case "lol" with a "Runtime error "5" - Invalid procedure call or argument". I tried to ? RangeToFormat.Address and it shows the correct range address... What is wrong with it?

Noldor130884

Well the credit for this answer all goes to Axel Richter:

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

As you can see, the formulas are not formulas anymore, but integers! That works flawlessly

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Excel VBA - conditional formatting, Index not included in the interval

분류에서Dev

Issue with macro relating to conditional formatting in Excel VBA

분류에서Dev

Excel 2010 MATCH function returns an error in conditional formatting

분류에서Dev

Excel 2010 Starts with a grey screen, won't open file

분류에서Dev

Protect formatting in Excel 2010, and allow editing of text

분류에서Dev

Filter on conditional formatting in excel sheet using pandas

분류에서Dev

Excel 2010 VBA & ActiveX functions not responding

분류에서Dev

Excel 2010과 2013 (OLEObject)간에 VBA 명령이 호환되지 않습니까?

분류에서Dev

How do I add conditional formatting to cells containing #N/A in Excel?

분류에서Dev

Excel: Conditional formatting not filling in cells if adjacent cell is filled

분류에서Dev

Importing excel file with all the conditional formatting rules to epplus

분류에서Dev

Use Excel conditional formatting based on display value and not cell value

분류에서Dev

Excel: Using text from a cell as the name of a worksheet in a conditional formatting equation

분류에서Dev

Visual Studio의 Excel 2010 및 Excel 2013 용 Excel 추가 기능

분류에서Dev

VBA 코드는 Excel 2013에서 실행되지만 2010에서는 실행되지 않습니다.

분류에서Dev

Excel VBA가 포함 된 Outlook 2010 GAL

분류에서Dev

Excel 2010의 VBA 위치 차트

분류에서Dev

VBA-Excel 2010 Macro Error "memeber or data method not found"

분류에서Dev

bash 메뉴에서 Excel 2010 vba 호출

분류에서Dev

bash 메뉴에서 Excel 2010 vba 호출

분류에서Dev

Excel 2010을 삭제하는 VBA 코드

분류에서Dev

Issue reading hidden column using VBA in Excel 2013

분류에서Dev

Updating VBA API to 64-bit Excel 2013

분류에서Dev

VBA-자동화 오류-Excel 2013

분류에서Dev

Excel 2010에서 Excel 2013으로 업그레이드 한 후 VBA의 대형 배열에서 '메모리 부족'오류 발생

분류에서Dev

Excel 2013에서는 작동하지만 Excel 2010에서는 작동하지 않는 VBA를 사용하여 피벗 테이블 삽입, 코드 변경 없음

분류에서Dev

Excel 2010 VBA 매크로 만들기 Excel 동결

분류에서Dev

EXCEL 2010 if 문

분류에서Dev

Why can't I do math inside of MAX() in Excel 2010?

Related 관련 기사

  1. 1

    Excel VBA - conditional formatting, Index not included in the interval

  2. 2

    Issue with macro relating to conditional formatting in Excel VBA

  3. 3

    Excel 2010 MATCH function returns an error in conditional formatting

  4. 4

    Excel 2010 Starts with a grey screen, won't open file

  5. 5

    Protect formatting in Excel 2010, and allow editing of text

  6. 6

    Filter on conditional formatting in excel sheet using pandas

  7. 7

    Excel 2010 VBA & ActiveX functions not responding

  8. 8

    Excel 2010과 2013 (OLEObject)간에 VBA 명령이 호환되지 않습니까?

  9. 9

    How do I add conditional formatting to cells containing #N/A in Excel?

  10. 10

    Excel: Conditional formatting not filling in cells if adjacent cell is filled

  11. 11

    Importing excel file with all the conditional formatting rules to epplus

  12. 12

    Use Excel conditional formatting based on display value and not cell value

  13. 13

    Excel: Using text from a cell as the name of a worksheet in a conditional formatting equation

  14. 14

    Visual Studio의 Excel 2010 및 Excel 2013 용 Excel 추가 기능

  15. 15

    VBA 코드는 Excel 2013에서 실행되지만 2010에서는 실행되지 않습니다.

  16. 16

    Excel VBA가 포함 된 Outlook 2010 GAL

  17. 17

    Excel 2010의 VBA 위치 차트

  18. 18

    VBA-Excel 2010 Macro Error "memeber or data method not found"

  19. 19

    bash 메뉴에서 Excel 2010 vba 호출

  20. 20

    bash 메뉴에서 Excel 2010 vba 호출

  21. 21

    Excel 2010을 삭제하는 VBA 코드

  22. 22

    Issue reading hidden column using VBA in Excel 2013

  23. 23

    Updating VBA API to 64-bit Excel 2013

  24. 24

    VBA-자동화 오류-Excel 2013

  25. 25

    Excel 2010에서 Excel 2013으로 업그레이드 한 후 VBA의 대형 배열에서 '메모리 부족'오류 발생

  26. 26

    Excel 2013에서는 작동하지만 Excel 2010에서는 작동하지 않는 VBA를 사용하여 피벗 테이블 삽입, 코드 변경 없음

  27. 27

    Excel 2010 VBA 매크로 만들기 Excel 동결

  28. 28

    EXCEL 2010 if 문

  29. 29

    Why can't I do math inside of MAX() in Excel 2010?

뜨겁다태그

보관