mattadams84
Board Regular
- Joined
- Oct 30, 2016
- Messages
- 54
Hello
I have got a spreadsheet that with through various help from this forum is working perfectly. I am now in the process of 'improving' it. Here is how it works:
I have a 'data sheet' that is 294 columns wide, and contains lots of data for football matches. My spreadsheet currently goes through all of the data and when various criteria are met it adds the match to a different sheet. At the moment what happens is that each row on my selections sheet contains a match and the columns hold the data. This works perfectly.
So for example :
ROW 3, column A (home team), column B (away team), column C (some data), column D (some data) etc...
I want to change it so that instead of having the match on one row, id like to split it to two rows. The simple reason for this is so that i gain a bit of space and it becomes more readable.
So for example i want it to read :
ROW 3 (home team) and the columns hold all the data for the home team.
ROW 4 (away team) and the columns hold all the data for the away team.
Here is my original VBA code :
And now, here is what i have tried to make it work as i want...
This does not work though. In fact it crashes excel. Can anyone help me achieve what i want?
There is a slight snag. As you can see the first peice of data is common to both teams (it is basically the name of the league) Is there anyway to tell excel to merge the two rows for column B?
Here is a link to my spreadsheet:
https://www.dropbox.com/sh/ddwr5tnchu5elnk/AABbEdY4j_Z316cjPJ9X_9zEa?dl=0
Regards
I have got a spreadsheet that with through various help from this forum is working perfectly. I am now in the process of 'improving' it. Here is how it works:
I have a 'data sheet' that is 294 columns wide, and contains lots of data for football matches. My spreadsheet currently goes through all of the data and when various criteria are met it adds the match to a different sheet. At the moment what happens is that each row on my selections sheet contains a match and the columns hold the data. This works perfectly.
So for example :
ROW 3, column A (home team), column B (away team), column C (some data), column D (some data) etc...
I want to change it so that instead of having the match on one row, id like to split it to two rows. The simple reason for this is so that i gain a bit of space and it becomes more readable.
So for example i want it to read :
ROW 3 (home team) and the columns hold all the data for the home team.
ROW 4 (away team) and the columns hold all the data for the away team.
Here is my original VBA code :
Code:
Sub LTATrades()
Application.ScreenUpdating = False
Dim LastRow As Long, fs As Worksheet, ds As Worksheet, x As Long
Set fs = Sheets("Filters")
Set ds = Sheets("Data")
LastRow = ds.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ClearSelections
SortData
DeleteCF
For x = 4 To LastRow
If ds.Cells(x, 1) = ds.Range("E1") And ds.Cells(x, 40) >= fs.Range("C2") And ds.Cells(x, 41) >= fs.Range("C2") Then
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "B").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 3)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "C").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 4)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "D").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 5)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "E").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 81)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "F").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 91)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "G").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 82)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "H").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 92)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "I").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 83)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "J").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 93)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "K").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 84)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "L").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 94)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "M").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 85)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "N").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 96)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "O").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 95)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "P").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 86)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "Q").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 88)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "R").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 98)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "S").End(xlUp).Offset(1, 0).Value = Round((ds.Cells(x, 57).Value / ds.Cells(x, 40).Value) * 100, 0) & "% (" & ds.Cells(x, 57).Value & "/" & ds.Cells(x, 40).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "T").End(xlUp).Offset(1, 0).Value = Round((ds.Cells(x, 71).Value / ds.Cells(x, 41).Value) * 100, 0) & "% (" & ds.Cells(x, 71).Value & "/" & ds.Cells(x, 41).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "U").End(xlUp).Offset(1, 0).Value = Round((ds.Cells(x, 58).Value / ds.Cells(x, 40).Value) * 100, 0) & "% (" & ds.Cells(x, 58).Value & "/" & ds.Cells(x, 40).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "V").End(xlUp).Offset(1, 0).Value = Round((ds.Cells(x, 72).Value / ds.Cells(x, 41).Value) * 100, 0) & "% (" & ds.Cells(x, 72).Value & "/" & ds.Cells(x, 41).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "W").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 229).Value + ds.Cells(x, 243).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 229).Value + ds.Cells(x, 243).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "X").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 257).Value + ds.Cells(x, 275).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 257).Value + ds.Cells(x, 275).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "Y").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 54).Value + ds.Cells(x, 68).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 54).Value + ds.Cells(x, 68).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "Z").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 55).Value + ds.Cells(x, 69).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 55).Value + ds.Cells(x, 69).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "AA").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 56).Value + ds.Cells(x, 70).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 56).Value + ds.Cells(x, 70).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "AB").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 59).Value + ds.Cells(x, 73).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 59).Value + ds.Cells(x, 73).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "AC").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 144).Value + ds.Cells(x, 159).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 144).Value + ds.Cells(x, 159).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "AD").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 147).Value + ds.Cells(x, 162).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 147).Value + ds.Cells(x, 162).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
End If
Next x
ResetCFLTA
Application.ScreenUpdating = True
End Sub
Code:
Sub LTATradesTest()
Application.ScreenUpdating = False
Dim LastRow As Long, fs As Worksheet, ds As Worksheet, x As Long
Set fs = Sheets("Filters")
Set ds = Sheets("Data")
LastRow = ds.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ClearSelections
SortData
For x = 4 To LastRow
If ds.Cells(x, 1) = ds.Range("E1") And ds.Cells(x, 40) >= fs.Range("C2") And ds.Cells(x, 41) >= fs.Range("C2") Then
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "B").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 3)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "C").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 4)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "C").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 5)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "D").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 81)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "D").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 91)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "E").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 82)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "E").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 92)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "F").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 83)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "F").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 93)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "G").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 84)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "G").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 94)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "H").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 85)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "H").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 96)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "I").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 95)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "I").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 86)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "J").End(xlUp).Offset(1, 0).Value = ds.Cells(x, 88)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "J").End(xlUp).Offset(2, 0).Value = ds.Cells(x, 98)
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "K").End(xlUp).Offset(1, 0).Value = Round((ds.Cells(x, 57).Value / ds.Cells(x, 40).Value) * 100, 0) & "% (" & ds.Cells(x, 57).Value & "/" & ds.Cells(x, 40).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "K").End(xlUp).Offset(2, 0).Value = Round((ds.Cells(x, 71).Value / ds.Cells(x, 41).Value) * 100, 0) & "% (" & ds.Cells(x, 71).Value & "/" & ds.Cells(x, 41).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "L").End(xlUp).Offset(1, 0).Value = Round((ds.Cells(x, 58).Value / ds.Cells(x, 40).Value) * 100, 0) & "% (" & ds.Cells(x, 58).Value & "/" & ds.Cells(x, 40).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "L").End(xlUp).Offset(2, 0).Value = Round((ds.Cells(x, 72).Value / ds.Cells(x, 41).Value) * 100, 0) & "% (" & ds.Cells(x, 72).Value & "/" & ds.Cells(x, 41).Value & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "M").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 229).Value + ds.Cells(x, 243).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 229).Value + ds.Cells(x, 243).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "M").End(xlUp).Offset(2, 0).Value = Round(((ds.Cells(x, 257).Value + ds.Cells(x, 275).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 257).Value + ds.Cells(x, 275).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "N").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 54).Value + ds.Cells(x, 68).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 54).Value + ds.Cells(x, 68).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "N").End(xlUp).Offset(2, 0).Value = Round(((ds.Cells(x, 55).Value + ds.Cells(x, 69).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 55).Value + ds.Cells(x, 69).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "O").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 56).Value + ds.Cells(x, 70).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 56).Value + ds.Cells(x, 70).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "O").End(xlUp).Offset(2, 0).Value = Round(((ds.Cells(x, 59).Value + ds.Cells(x, 73).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 59).Value + ds.Cells(x, 73).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "P").End(xlUp).Offset(1, 0).Value = Round(((ds.Cells(x, 144).Value + ds.Cells(x, 159).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 144).Value + ds.Cells(x, 159).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
Sheets("LTA").Cells(Sheets("LTA").Rows.Count, "P").End(xlUp).Offset(2, 0).Value = Round(((ds.Cells(x, 147).Value + ds.Cells(x, 162).Value) / (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value)) * 100, 0) & "% (" & (ds.Cells(x, 147).Value + ds.Cells(x, 162).Value) & "/" & (ds.Cells(x, 40).Value + ds.Cells(x, 41).Value) & ")"
End If
Next x
Application.ScreenUpdating = True
End Sub
This does not work though. In fact it crashes excel. Can anyone help me achieve what i want?
There is a slight snag. As you can see the first peice of data is common to both teams (it is basically the name of the league) Is there anyway to tell excel to merge the two rows for column B?
Here is a link to my spreadsheet:
https://www.dropbox.com/sh/ddwr5tnchu5elnk/AABbEdY4j_Z316cjPJ9X_9zEa?dl=0
Regards