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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,215,565
Messages
6,125,583
Members
449,237
Latest member
Chase S

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