I am trying to write a VBA macro which colours one cell (E) based on the data in two other cells (A) and (C). The macro keep falling over on the Set wsData line, generating an RTE 9 - subscript out of range error
Here is the code
Sub LDT1_HOME_GREEN()
Dim wsData As Worksheet
Dim rAnchorCell As Range
Dim iDataRowsCount As Long
Dim iDataRow As Long
Dim asLeagues() As String
Dim iLeaguesCount As Long
Dim iLeague As Long
Set wsData = thisWorkbook.Worksheets("Lay The Draw")
Set rAnchorCell = wsData.Range("A1") '<= this is where data starts
iDataRowsCount = rAnchorCell.Offset(100000).End(xlUp).Row - rAnchorCell.Row + 1
iLeaguesCount = 25
ReDim asLeagues(iLeaguesCount)
asLeagues(1) = "Austria: 2. Liga"
asLeagues(2) = "Australia: A-League"
asLeagues(3) = "Bulgaria: Parva Liga"
asLeagues(4) = "Czech Republic: Czech Liga"
asLeagues(5) = "Denmark: Superliga"
asLeagues(6) = "Germany: Bundesliga II"
asLeagues(7) = "Greece: Superleague"
asLeagues(8) = "Hungary: NB I"
asLeagues(9) = "Portugal: Primeira Liga"
asLeagues(10) = "Portugal: Segunda Liga"
asLeagues(11) = "Poland: Ekstraklasa"
asLeagues(12) = "Qatar: Q League"
asLeagues(13) = "Turkey: Super Lig"
asLeagues(14) = "Chile: Primera Division"
asLeagues(15) = "Colombia: Primera A"
asLeagues(16) = "Ecuador: Primera B"
asLeagues(17) = "Iceland: Inkasso-Deildin"
asLeagues(18) = "Ireland: Premier Division"
asLeagues(19) = "Korea: K-League Classic"
asLeagues(20) = "Lithuania: A Lyga"
asLeagues(21) = "Norway: Elieserien"
asLeagues(22) = "Peru: Segunda Division"
asLeagues(23) = "Sweden: Superettan"
asLeagues(24) = "Sweden: Division 1 - Sodra"
asLeagues(25) = "USA: MLS"
For iDataRow = 1 To iDataRowsCount
If rAnchorCell.Cells(iDataRow) Like "LTD1_HOME*" _
Then
For iLeague = 1 To iLeaguesCount
If rAnchorCell.Cells(iDataRow, 3) Like "*" & asLeagues(iLeague) & "*" _
Then
With rAnchorCell.Cells(iDataRow, 5).Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 5230738
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next iLeague
End If
Next iDataRow
End Sub
Any help gladly accepted
Bookmarks