Trying to move data from every 3rd row to up 1

Mo0nlight

New Member
Joined
Jan 8, 2018
Messages
5
Hello all,

I'm trying to create a VBA macro to move the yellow highlight cells to the green cell just like how you see it in the picture below.

Excel%20snapshot.PNG


The amount of rows of information can be from 40 line to 900 so I would need something that would continue moving cells over until there isn't any more information in Columns A-I.

The ideal result show reflect like this for as many rows as needed.

Excel%20snapshot%202.PNG


I'm still pretty new the VBA world and have created some for other proposes but I just can't seem tot figure this one out.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Welcome to the Board!

Your image attempts are not working. There are tools you can use to post screen images. They are listed in Section B of this link here: http://www.mrexcel.com/forum/board-a...forum-use.html.
Also, there is a Test Here forum on this board that you can use to test out these tools to make sure they are working correctly before using them in your question.
 
Upvote 0
I am unable to access those sites or down load files from the internet from my current location (my workplace security blocks all of that for security reasons). Many other users have the same security concerns.
That is why I recommend using those tools mentioned, if possible.

Perhaps someone who can will take a look at those images. If not, I will see if I can get find some time tonight when I am at home.
 
Upvote 0
Give this macro a try...
Code:
Sub MoveData()
  Dim R As Long
  For R = 2 To Cells(Rows.Count, "A").End(xlUp).Row Step 3
    Cells(R, "A").Resize(, 3).Cut Cells(R - 1, "J")
    Cells(R, "F").Resize(, 4).Cut Cells(R - 1, "O")
  Next
End Sub
 
Upvote 0
I actually resolved this with those code. I have i as 4 because there are often times that the first 5 rows do not need to be moved.

Sub CopyCells1()
Dim i As Long, lastRow As Long, rngToMove As Range


lastRow = Worksheets("cxl macro test").Cells(1048576, 1).End(xlUp).Row


For i = 4 To lastRow
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 10) = Worksheets("cxl macro test").Cells(i - 1, 1)​
Worksheets("cxl macro test").Cells(i - 1, 1) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 11) = Worksheets("cxl macro test").Cells(i - 1, 2)
Worksheets("cxl macro test").Cells(i - 1, 2) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 12) = Worksheets("cxl macro test").Cells(i - 1, 3)
Worksheets("cxl macro test").Cells(i - 1, 3) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 13) = Worksheets("cxl macro test").Cells(i - 1, 4)
Worksheets("cxl macro test").Cells(i - 1, 4) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 14) = Worksheets("cxl macro test").Cells(i - 1, 5)
Worksheets("cxl macro test").Cells(i - 1, 5) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 15) = Worksheets("cxl macro test").Cells(i - 1, 6)
Worksheets("cxl macro test").Cells(i - 1, 6) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 16) = Worksheets("cxl macro test").Cells(i - 1, 7)
Worksheets("cxl macro test").Cells(i - 1, 7) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 17) = Worksheets("cxl macro test").Cells(i - 1, 8)
Worksheets("cxl macro test").Cells(i - 1, 8) = ""​
End If
If Worksheets("cxl macro test").Cells(i, 1) = "" And Worksheets("cxl macro test").Cells(i - 3, 1) = "" Then
Worksheets("cxl macro test").Cells(i - 2, 18) = Worksheets("cxl macro test").Cells(i - 1, 9)
Worksheets("cxl macro test").Cells(i - 1, 9) = ""​
End If​
Next i​

Although for some reason, I can't get it to review the last row of contents and it doesn't move the required row. Does anyone know how i should tweek it?
 
Upvote 0
This was solved by adding +2 at the end of my code

lastRow = Worksheets("cxl macro test").Cells(Rows.Count, "A").End(xlUp).Row + 2


​thank you all for helping!!!
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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