ProphetofProfit
New Member
- Joined
- Feb 28, 2011
- Messages
- 28
Hello! The code below runs fine for 800 rows, and then on row 801 it mysteriously ceases to operate. What it does is reads a value in column C of worksheet "games", finds this same value in "teams" and then pastes some values from "teams" to "games". As I said, it works like a dream for 800 rows and then for this particular row, empty cells are being pasted across worksheets.
I've checked that there is numbers to paste from "teams" to "games"
The identifying values are identical. The macro sees 'Verona' in "games" then looks up "Verona" in sheets and they are spelt the same.
When the above happens, my spreadsheet spits out a lot of #DIV/0! errors which leads to a runtime error further down the line. The original problem is the above.
I've checked that there is numbers to paste from "teams" to "games"
The identifying values are identical. The macro sees 'Verona' in "games" then looks up "Verona" in sheets and they are spelt the same.
When the above happens, my spreadsheet spits out a lot of #DIV/0! errors which leads to a runtime error further down the line. The original problem is the above.
Code:
Sub macro1()
Dim i
Dim r
For r = Sheets("Parameters").Range("B9") To Sheets("Parameters").Range("B10")
'for home team
For i = Sheets("Parameters").Range("B11") To Sheets("Parameters").Range("B12")
'Update the Division if you find the team and if the division is left blank (Home Team)
If Sheets("teams").Cells(i, 1).Value = Sheets("games").Cells(r, 4).Value And Sheets("teams").Cells(i, 2).Value = "" Then
Sheets("teams").Cells(i, 2).Value = Sheets("games").Cells(r, 1).Value
End If
Next i
For i = Sheets("Parameters").Range("B11") To Sheets("Parameters").Range("B12")
'Update the home team values
If Sheets("teams").Cells(i, 1).Value = Sheets("games").Cells(r, 4).Value Then
'if divisions are same
If Sheets("games").Cells(r, 1).Value = Sheets("teams").Cells(i, 2).Value Then
Sheets("games").Cells(r, 16).Value = Sheets("teams").Cells(i, 3).Value
Sheets("games").Cells(r, 17).Value = Sheets("teams").Cells(i, 4).Value
Sheets("games").Cells(r, 18).Value = Sheets("teams").Cells(i, 5).Value
Sheets("games").Cells(r, 19).Value = Sheets("teams").Cells(i, 6).Value
Sheets("games").Cells(r, 20).Value = Sheets("teams").Cells(i, 7).Value
Sheets("games").Cells(r, 21).Value = Sheets("teams").Cells(i, 8).Value
Sheets("games").Cells(r, 22).Value = Sheets("teams").Cells(i, 9).Value
Sheets("games").Cells(r, 23).Value = Sheets("teams").Cells(i, 10).Value
Sheets("games").Cells(r, 24).Value = Sheets("teams").Cells(i, 11).Value
Sheets("games").Cells(r, 25).Value = Sheets("teams").Cells(i, 12).Value
End If
'D1 and D2 combination
If Sheets("games").Cells(r, 1).Value = "D1" And Sheets("teams").Cells(i, 2).Value = "D2" Then
Sheets("games").Cells(r, 16).Value = Sheets("teams").Cells(i, 3).Value * Sheets("parameters").Range("f3").Value
Sheets("games").Cells(r, 17).Value = Sheets("teams").Cells(i, 4).Value * Sheets("parameters").Range("g3").Value
Sheets("games").Cells(r, 18).Value = Sheets("teams").Cells(i, 5).Value * Sheets("parameters").Range("f3").Value
Sheets("games").Cells(r, 19).Value = Sheets("teams").Cells(i, 6).Value * Sheets("parameters").Range("g3").Value
Sheets("games").Cells(r, 20).Value = Sheets("teams").Cells(i, 7).Value
Sheets("games").Cells(r, 21).Value = Sheets("teams").Cells(i, 8).Value
Sheets("games").Cells(r, 22).Value = Sheets("teams").Cells(i, 9).Value
Sheets("games").Cells(r, 23).Value = Sheets("teams").Cells(i, 10).Value
Sheets("games").Cells(r, 24).Value = Sheets("teams").Cells(i, 11).Value
Sheets("games").Cells(r, 25).Value = Sheets("teams").Cells(i, 12).Value