Consulting

Results 1 to 5 of 5

Thread: Run-time error for Highlighting

  1. #1
    VBAX Regular
    Joined
    Apr 2009
    Posts
    59
    Location

    Run-time error for Highlighting

    I get the following error message and have now idea why or how to fix it

    Run-time error '-2147417848 (80010108)':
    Method 'ColorIndex' of object 'Font' failed

    Any ideas?


    MODULE1:
    [VBA]
    Sub color_cells(fire_rng As Range)
    For Each C In fire_rng
    If IsNumeric(C.Offset(0, -3).Value) Then
    If C.Value < 0 Then
    Range(C, C.Offset(0, -4)).Interior.ColorIndex = 9
    Range(C, C.Offset(0, -5)).Font.ColorIndex = 2
    C.Offset(0, -5) = "HI"
    C.Offset(0, -5).Interior.ColorIndex = 3
    Else
    Range(C, C.Offset(0, -4)).Interior.ColorIndex = 1
    Range(C, C.Offset(0, -4)).Font.ColorIndex = 2
    If Not C.Offset(0, -5).Value = "HI" _
    And Not C.Offset(0, -5).Value = "LO" Then
    C.Offset(0, -5).Interior.ColorIndex = 1
    C.Offset(0, -5).Font.ColorIndex = 2
    End If
    End If
    Next C
    End Sub
    [/VBA]

    It highlights the line with Font.ColorIndex

    [VBA]Sub main()
    Call color_cells(ActiveSheet.Range("f2:f60"))
    Call color_cells(ActiveSheet.Range("l2:L60"))
    Call color_cells(ActiveSheet.Range("r2:r60"))
    End Sub[/VBA]

    SHEET1:
    [VBA]
    Private Sub Worksheet_calculate()
    Call main
    End Sub[/VBA]

    So main is being called all the time as values in sheet columns F, L and R are changing often.

    If i click debug, then try to resume, it says: Out of Memory...

    I just restarted and got the same error.
    Last edited by frubeng; 05-25-2010 at 04:18 AM.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,089
    Location
    Yes..... Don't bother closing the workbook and run like hell.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,089
    Location
    Seriously, what are we to make of your initial post? You failed to mention the section of code you were trying to run at the time of this error message, or even produce a sample workbook for us to view the how why when or oops factor, so how are we expected to provide you with an answer.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    VBAX Regular
    Joined
    Apr 2009
    Posts
    59
    Location
    Quote Originally Posted by Aussiebear
    Seriously, what are we to make of your initial post? You failed to mention the section of code you were trying to run at the time of this error message, or even produce a sample workbook for us to view the how why when or oops factor, so how are we expected to provide you with an answer.
    Yes sorry, added all the info, thanks for any help!

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Your code will fail if C is in row 5 or above. There is then no c.offset(,-5).
    A sample file would assist.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •