How I move the cells from one side to another depending on another cells in Excel VBA?

Eddy_2017

New Member
Joined
Sep 19, 2017
Messages
2
Hello I need a little help, I started to learn Excel VBA of a few and that's why I make this appeal to you.
I need a VBA code which to replace him the bottom one (that goes, but to enter a code of 20,000 lines seems too many, isn't it?)


On short, my problem is :


In an Excel sheet I have a table with basketball players and their stats at each match, only that they don't play all matches played by their teams in a season. After my calculations an NBA team could play about 111-115 matches in a season, putting here and all matches in Play Offs - 7 games x 4 phases. So I approximated at 120 stages played by each team, that I have placed them from D6:DS6, below from D7: DS20 I put the stages played by each player with their stats (from D7 to DS7 even specific which is the match he played by him from 1 to 120), which can be differently understood by Excel, that putting them next to each other as if they were played consecutively (This arrangement comes from another VBA code but I do not want to change it), to better understand what I want to say, I give an example : a player plays stages 1, 16-32, 34, 58-71 in a total of 33 stages, all this I want them placed under the number of the stage played by his team, ie 1, 16-32, 34, 58-71, I do not want them next to others exacly as I explained before, so between stages 1 and 16 I need 14 free spaces, between stages 32 and 34 I need 1 free spaces, between stages 34 and 58 I need 23 free spaces, but I don't want to do this thing manually and I can't figure amount how I could make it easier, without having to enter a 20000-row code



Sub MoveStagePlayedPlayer ()


Dim StagePlayedPlayer As Variant


StagePlayedPlayer = Sheet1.Range("DR7").Value


If StagePlayedPlayer = 120 Then
Sheet1.Range("DR7:DR20").Cut Range("DS7")
End If


StagePlayedPlayer = Sheet1.Range("DQ7").Value


If StagePlayedPlayer = 120 Then
Sheet1.Range("DQ7:DQ20").Cut Range("DS7")
ElseIf StagePlayedPlayer = 119 Then
Sheet1.Range("DQ7:DQ20").Cut Range("DR7")
End If


StagePlayedPlayer = Sheet1.Range("DP7").Value


If StagePlayedPlayer = 120 Then
Sheet1.Range("DP7:DP20").Cut Range("DS7")
ElseIf StagePlayedPlayer = 119 Then
Sheet1.Range("DP7:DP20").Cut Range("DR7")
ElseIf StagePlayedPlayer = 118 Then
Sheet1.Range("DP7:DP20").Cut Range("DQ7")
End If


StagePlayedPlayer = Sheet1.Range("DO7").Value


If StagePlayedPlayer = 120 Then
Sheet1.Range("DO7:DO20").Cut Range("DS7")
ElseIf StagePlayedPlayer = 119 Then
Sheet1.Range("DO7:DO20").Cut Range("DR7")
ElseIf StagePlayedPlayer = 118 Then
Sheet1.Range("DO7:DO20").Cut Range("DQ7")
ElseIf StagePlayedPlayer = 117 Then
Sheet1.Range("DO7:DO20").Cut Range("DP7")
End If

End Sub


The above code manages to move the string of rows about I spoke you, leaving the desired spaces, for example DR7 string: DR20 will be moved to DS7: DS20 only if in the DR7 cell is the specified number of the stage played by player, but I return to what I said, there are not many 20000 thousand lines


Thanks in advance for your help! I hope the explanation has been coherent?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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