Not sure why this code stops??

chinchi81

Board Regular
Joined
Jul 13, 2007
Messages
69
Hi,

I have the following code but it keeps on stopping at myHomeAwayCol = 18 and I am not sure why. Doe anyone have any ideas?

Cheers,
Phil


Code:
Sub PhilsCode2()

ChDir "E:\Football Betting"
    Workbooks.Open Filename:="E:\Football Betting\Football Results.xls"
    Windows("Belgium - Jupiler League.xls").Activate
    Sheets("2007-2008").Select
    Range("A3:AE308").Select
    Range("AE308").Activate
    Selection.Interior.ColorIndex = xlNone
    Selection.Font.Bold = False

On Error GoTo myEnd

Dim myRow As Long
Dim myValue As String

 myHomeAwayCol = 13
 myGoalsCol = 14
 myAll = 31
 myRow = 3
 
For myRow = 3 To 308 'number of rows to look @

    Select Case Cells(myRow, myHomeAwayCol)
        Case "H"
            If Cells(myRow, myGoalsCol).Value >= 2.5 And Cells(myRow, myAll).Value = "HHH" Then
                Call myHighlight(myRow)
            End If
            
            If Cells(myRow, myGoalsCol).Value >= 1 And Cells(myRow, myGoalsCol).Value <= 2 And Cells(myRow, myAll).Value = "HHH" Then
                Call myHighlight(myRow)
            End If
        Case "A"
            If Cells(myRow, myGoalsCol).Value >= -1.5 And Cells(myRow, myGoalsCol).Value <= 0 And Cells(myRow, myAll).Value = "AAA" Then
                Call myHighlight(myRow)
            End If
        End Select
Next

 On Error GoTo myEnd
 
 myHomeAwayCol = 18
 myGoalsCol = 19
 myAll = 31
 myRow = 3
 


For myRow = 3 To 308 'number of rows to look @

    Select Case Cells(myRow, myHomeAwayCol)
        Case "H"
            If Cells(myRow, myGoalsCol).Value >= 2.5 And Cells(myRow, myAll).Value = "HHH" Then
                Call myHighlight1(myRow)
            End If
            
            If Cells(myRow, myGoalsCol).Value >= 1.5 And Cells(myRow, myGoalsCol).Value <= 2 And Cells(myRow, myAll).Value = "HHH" Then
                Call myHighlight1(myRow)
            End If
        
            If Cells(myRow, myGoalsCol).Value >= 0 And Cells(myRow, myGoalsCol).Value <= 0.5 And Cells(myRow, myAll).Value = "HHH" Then
                Call myHighlight1(myRow)
            End If
        
        Case "D"
            If Cells(myRow, myGoalsCol).Value >= 0 And Cells(myRow, myGoalsCol).Value <= 0.5 And Cells(myRow, myAll).Value = "DDD" Or "ADD" Or "AAD" Then
                Call myHighlight1(myRow)
            End If
        
        Case "A"
           If Cells(myRow, myGoalsCol).Value >= 1.5 And Cells(myRow, myGoalsCol).Value <= 2 And Cells(myRow, myAll).Value = "AAA" Then
                Call myHighlight1(myRow)
            End If
            
            If Cells(myRow, myGoalsCol).Value >= -1.5 And Cells(myRow, myGoalsCol).Value <= 0 And Cells(myRow, myAll).Value = "AAA" Then
                Call myHighlight1(myRow)
            End If
        End Select
Next
 
 On Error GoTo myEnd

 myHomeAwayCol = 23
 myGoalsCol = 24
 myAll = 31
 myRow = 3
 
For myRow = 3 To 308 'number of rows to look @

    Select Case Cells(myRow, myHomeAwayCol)
        Case "H"
            If Cells(myRow, myGoalsCol).Value >= 0 And Cells(myRow, myGoalsCol).Value <= 0.5 And Cells(myRow, myAll).Value = "HHH" Then
                Call myHighlight2(myRow)
            End If
        
        Case "D"
            If Cells(myRow, myGoalsCol).Value >= -1.5 And Cells(myRow, myGoalsCol).Value <= -1 And Cells(myRow, myAll).Value = "DDD" Or "ADD" Or "AAD" Then
                Call myHighlight2(myRow)
            End If
        
        Case "A"
           If Cells(myRow, myGoalsCol).Value >= 2.5 And Cells(myRow, myAll).Value = "AAA" Then
                Call myHighlight2(myRow)
            End If
            
            If Cells(myRow, myGoalsCol).Value <= -1.5 And Cells(myRow, myAll).Value = "AAA" Then
                Call myHighlight2(myRow)
            End If
           
           If Cells(myRow, myGoalsCol).Value >= -1 And Cells(myRow, myGoalsCol).Value <= 0 And Cells(myRow, myAll).Value = "AAA" Then
                Call myHighlight2(myRow)
            End If
        End Select
Next
myEnd:

End Sub


Function myHighlight(myRow As Long)

    Range("A" & myRow & ":C" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With
        
    Range("J" & myRow & ":N" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With

    Range("AE" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With

End Function

Function myHighlight1(myRow As Long)
Range("A" & myRow & ":C" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With
        
    Range("O" & myRow & ":S" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With

Range("AE" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With

End Function

Function myHighlight2(myRow As Long)
Range("A" & myRow & ":C" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With
        
    Range("T" & myRow & ":X" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With

Range("AE" & myRow).Select
        With Selection.Interior
            .ColorIndex = 8
            .PatternColorIndex = xlAutomatic
            Selection.Font.Bold = True
        End With

End Function

[Added code tags~VP]
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
What error message do you get if you remove the two earlier lines that read "On Error GoTo myEnd" ?
 
Upvote 0
Have you tried:
- stepping through the code to see what is happening?
- removing the 'goto myend' error trapping to see if there is an error occurring and what it is?
 
Upvote 0
Do you have a breakpoint on the line "myHomeAwayCol = 18" ?

If so, remove the breakpoint.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top