Excel VBA Loop then Delete

XfortunaX

New Member
Joined
Aug 28, 2014
Messages
28
Hi,

This sounds simple, but I am stuck. I am looking for a simple loop that will count the number of rows down then start the process of moving B2:E2 to C1:F1 then B4:E4 to C3:F3 and so on until there are not anymore rows.

In the end, it will use the following to delete all rows that do not have information in B.

Code:
Sub MoveCellsUp()

    Dim lr As Long

    lr = Range("A1").End(xlDown).Row

    'Loop that will cut and paste the cells up and over a row then move down to the next set

    'Delete all empty Rows
    [B:B].SpecialCells(xlBlanks).EntireRow.Delete

    End Sub

Thank you,

JT
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hope this helps.
Please save your data before run it.
Code:
Sub MoveCellsUp()
    Dim lr As Long, i As Long
    lr = Range("A1").End(xlDown).Row
    'Loop that will cut and paste the cells up and over a row then move down to the next set
    For i = lr To 2 Step -2
        Range(cells(i, 2), cells(i, 6)).Cut cells(i - 1, 3)
        Rows(i).Delete
    Next
End Sub
 
Upvote 0
Takae,

Thank you for the response. I am sorry on my late response.

The original data dump looks like:


After formatting:


The loop gets the price below (or prices) below the description and moves it to the right of the description then deletes the rows until it hits the next description.

I cannot get the loop to grab all of the information. Sometimes the data is columns out.

Thanks!

John
 
Last edited:
Upvote 0
The original data image above is correct, the second image is erroneous. Should be deleted.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,974
Messages
6,175,739
Members
452,667
Latest member
vanessavalentino83

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