Results 1 to 2 of 2

Thread: A VBA Excel Loop Question??

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    679

    A VBA Excel Loop Question??

    I need to loop though a range of cells but I need to skip those cells that have an AVERAGE formula in them...

    This is what I currently have:

    VB Code:
    1. Sheet1.Range("j6").Select
    2.  
    3. Do Until ActiveCell.Value = "N/A"
    4.     Select Case ActiveCell.Value
    5.         Case Is >= 70
    6.             ActiveCell.Font.ColorIndex = 1
    7.             ActiveCell.Interior.ColorIndex = 6
    8.         Case 62.4 To 69.4
    9.             ActiveCell.Font.ColorIndex = 1
    10.             ActiveCell.Interior.ColorIndex = 44
    11.         Case 54.4 To 62.4
    12.             ActiveCell.Font.ColorIndex = 1
    13.             ActiveCell.Interior.ColorIndex = 45
    14.         Case 45.4 To 54.4
    15.             ActiveCell.Font.ColorIndex = 1
    16.             ActiveCell.Interior.ColorIndex = 46
    17.         Case 37.4 To 45.4
    18.             ActiveCell.Font.ColorIndex = 1
    19.             ActiveCell.Interior.ColorIndex = 3
    20.         Case Is = ""
    21.             ActiveCell.Font.ColorIndex = 1
    22.             ActiveCell.Interior.ColorIndex = 2
    23.         Case Is <= 37
    24.             ActiveCell.Font.ColorIndex = 2
    25.             ActiveCell.Interior.ColorIndex = 1
    26.  
    27.     End Select
    28.    
    29.     ActiveCell.Offset(1, 0).Select
    30. Loop
    31.     Sheet1.Range("e4").Select
    This will work fine in color codeing the cells that fall in a range, but in the range that I am looping through there are rows that are designated for averaging specific cells...For example - Cells A1:A3 are averaged at A4...then A6:A9 are averaged at A10.

    The problem happens when there is no data in some of these cells that cause the AVERAGE to show -#DIV/0! this causes a Type Mismatch Error.

    Can someone please assist me with figuring this out?

    Thank you.

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Luton, UK
    Posts
    178
    If InStr(1, ActiveCell.Formula, "AVERAGE") <> 0 Then ...
    ...................
    Regards
    BrianB
    -------------------------------

Posting Permissions

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



Click Here to Expand Forum to Full Width