Results 1 to 5 of 5

How to stop a loop at a blank cell

Threaded View

  1. #1
    Registered User
    Join Date
    09-25-2007
    Posts
    5

    Question How to stop a loop at a blank cell

    So I've been trying to solve this problem for a while now... a few weeks. I'm trying to get this code to run down a column and fill the row in a certain color (not the entire row though, just the cells with text in them - if there is a better way to do it that would be great to know also! ) and STOP WHEN IT GETS TO A BLANK CELL!!! This seems to be a common theme, but I can't get the code from any of the other postings to work. No matter what I try, I just can't get it to stop! A bright and shiney gold star to anyone who can help...

    Here is my code:
    Sub Metrics()
    
        'Set MyCell as the range
        Dim MyCell As Range
        x = 2
        Columns("F:F").Select
        Do While Cells(x, 6).Value <> ""
        'Loop using a For Each…Next in selection
        For Each MyCell In Selection
            If MyCell.Value = "" Then
                'Clear the cell background color
                MyCell.Interior.ColorIndex = xlNone
                                            
            ElseIf MyCell.Value Like "*Go to*" Then
                'Set the cell background color to dark orange
                MyCell.Interior.ColorIndex = 46
                MyCell.Offset(0, -5).Interior.ColorIndex = 46
                MyCell.Offset(0, -4).Interior.ColorIndex = 46
                MyCell.Offset(0, -3).Interior.ColorIndex = 46
                MyCell.Offset(0, -2).Interior.ColorIndex = 46
                MyCell.Offset(0, -1).Interior.ColorIndex = 46
                MyCell.Offset(0, 1).Interior.ColorIndex = 46
                        
            ElseIf MyCell.Value Like "*Merged as child*" Then
                'Set the cell background color to light yellow
                MyCell.Interior.ColorIndex = 36
                MyCell.Offset(0, -5).Interior.ColorIndex = 36
                MyCell.Offset(0, -4).Interior.ColorIndex = 36
                MyCell.Offset(0, -3).Interior.ColorIndex = 36
                MyCell.Offset(0, -2).Interior.ColorIndex = 36
                MyCell.Offset(0, -1).Interior.ColorIndex = 36
                MyCell.Offset(0, 1).Interior.ColorIndex = 36
                                                           
            ElseIf MyCell.Value Like "*Approve with Mod*" Then
                'Set the cell background color to light green
                MyCell.Interior.ColorIndex = 35
                MyCell.Offset(0, -5).Interior.ColorIndex = 35
                MyCell.Offset(0, -4).Interior.ColorIndex = 35
                MyCell.Offset(0, -3).Interior.ColorIndex = 35
                MyCell.Offset(0, -2).Interior.ColorIndex = 35
                MyCell.Offset(0, -1).Interior.ColorIndex = 35
                MyCell.Offset(0, 1).Interior.ColorIndex = 35
                
            ElseIf MyCell.Value Like "*Approve*" Then
                'Set the cell background color to light periwinkle
                MyCell.Interior.ColorIndex = 34
                MyCell.Offset(0, -5).Interior.ColorIndex = 34
                MyCell.Offset(0, -4).Interior.ColorIndex = 34
                MyCell.Offset(0, -3).Interior.ColorIndex = 34
                MyCell.Offset(0, -2).Interior.ColorIndex = 34
                MyCell.Offset(0, -1).Interior.ColorIndex = 34
                MyCell.Offset(0, 1).Interior.ColorIndex = 34
                
            ElseIf MyCell.Value Like "*Withdrawal*" Then
                'Set the cell background color to light purple
                MyCell.Interior.ColorIndex = 39
                MyCell.Offset(0, -5).Interior.ColorIndex = 39
                MyCell.Offset(0, -4).Interior.ColorIndex = 39
                MyCell.Offset(0, -3).Interior.ColorIndex = 39
                MyCell.Offset(0, -2).Interior.ColorIndex = 39
                MyCell.Offset(0, -1).Interior.ColorIndex = 39
                MyCell.Offset(0, 1).Interior.ColorIndex = 39
                
            ElseIf MyCell.Value Like "*Disposition*" Then
                'Set the cell background color to lake blue
                'MyCell.Interior.ColorIndex = 33
            
            Else
                'Set the cell background color to gray
                MyCell.Interior.ColorIndex = 15
                MyCell.Offset(0, -5).Interior.ColorIndex = 15
                MyCell.Offset(0, -4).Interior.ColorIndex = 15
                MyCell.Offset(0, -3).Interior.ColorIndex = 15
                MyCell.Offset(0, -2).Interior.ColorIndex = 15
                MyCell.Offset(0, -1).Interior.ColorIndex = 15
                MyCell.Offset(0, 1).Interior.ColorIndex = 15
            End If
            
        Next
        Loop
    End Sub
    Last edited by sunandm00n; 09-25-2007 at 06:36 PM. Reason: illegal title, wrap code

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1