move contents down and replace contents and loop

loss1003

Board Regular
Joined
Jul 2, 2008
Messages
100
I’m looking for vba code to move down the cell contents in an active cell (column A) down one cell and move the cell contents underneath the active cell up one, by criteria, and repeat the loop until the first empty row in Column A
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Column A Column D<o:p></o:p>
Safety Vendor 5
General Vendor 3
Property Vendor 2<o:p></o:p>
Casualty Vendor 2
Taxi Vendor 5<o:p></o:p>
Products Vendor 10<o:p></o:p>
<o:p> </o:p><o:p> </o:p>
When the following criteria is meet in column D
>4
The active cell contents in column A drop down one cell and be replaced with the cell contents below. <o:p></o:p>
<o:p> </o:p>
If I ran the code the table above would now look: <o:p></o:p>
<o:p> </o:p>
Column A Column D<o:p></o:p>
General Vendor 3 (Moved Up One from orginial)
Safety Vendor 5 (Moved Down One from orginial)
Property Vendor 2
Casualty Vendor 2<o:p></o:p>
Products Vendor 10 (Moved Up One from orginial)
Taxi Vendor 5 (Moved Down One)

and would continue all the way down the columns until the first empty row.

Appreciate any assistance you can provide!
<o:p></o:p>
<o:p> </o:p>
Hope you can help<o:p></o:p>
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Sub Swapper()
For i = 1 To Range("A60000").End(xlUp).Row
If Cells(i, 4).Value > 4 Then
Rows(i).Cut
Rows(i + 2).Insert
i = i + 1
End If
Next
End Sub
 
Upvote 0
Sub Swapper()
For i = 1 To Range("A60000").End(xlUp).Row
If Cells(i, 4).Value > 4 Then
Rows(i).Cut
Rows(i + 2).Insert
i = i + 1
End If
Next
End Sub
Thanks the code works. How can I amend the code to continually loop until the following criteria is meet in each row.

If Cells(I, 4).Value > 2 And Cells(I, 3).Value = 1 Then

loop until?

For I = 1 To Range("A411").End(xlUp).Row
Do
If Cells(I, 4).Value > 2 And Cells(I, 3).Value = 1 Then
Rows(I).Cut
Rows(I + 2).Insert
I = I + 1
End If
Loop Until I = Cells(I, 4).Value > 2

Next

End Sub
 
Upvote 0
Sorry - I don't understand. Can you explain in English when you want the code to stop? And why cell A411 instead of A60000?
 
Upvote 0
I would like the code you provided for Range A2:A411 to continually/repeatedly loop <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Until all the rows meet these criteria:<o:p></o:p>
<o:p> </o:p>
If Cells(I, 3).Value = 1 And Cells(I, 4).Value > 2<o:p></o:p>
 
Upvote 0
This does what you asked, but might run forever!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Sub Swapper()<o:p></o:p>
Do Until Cells(I, 3).Value = 1 And Cells(I, 4).Value > 2 <o:p></o:p>
For i = 1 To Range("A60000").End(xlUp).Row
If Cells(i, 4).Value > 4 Then
Rows(i).Cut
Rows(i + 2).Insert
i = i + 1
End If
Next<o:p></o:p>

Wend
End Sub<o:p></o:p>

 
Upvote 0
This does what you asked, but might run forever!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Sub Swapper()<o:p></o:p>
Do Until Cells(I, 3).Value = 1 And Cells(I, 4).Value > 2<o:p></o:p>
For i = 1 To Range("A60000").End(xlUp).Row
If Cells(i, 4).Value > 4 Then
Rows(i).Cut
Rows(i + 2).Insert
i = i + 1
End If
Next<o:p></o:p>

Wend
End Sub<o:p></o:p>

Getting a compile error: Wend without While

Thanks,
 
Upvote 0
OK, I looked carefully at your request and now I know why it's not working -- I don't understand the question! You say:
...continually loop until the following criteria is meet in each row...
That doesn't make sense. If the criteria is not met in the row, then it will never be met and it will loop forever. Nothing in the code or requirements changes the values in columns 3 or 4.
So maybe you could better explain what you really want to do...?
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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