Repeating a macro til bottom line of data is reached

aquelious

New Member
Joined
Apr 27, 2016
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have the below macro that finds a blank cell in column A, then cuts the data from the row and pastes it into the row above in column C then deletes the empty row.
I want this to continue until I reach the last row of data in the spreadsheet but an struggling to work out how to do this.

Can anyone help?

Sub Macro1()
Dim ws As Worksheet
Dim x As Integer
Dim i As Long
Set ws = ActiveSheet
For Each cell In ws.Columns(1).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
ActiveCell.Offset(0, 1).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Cut
ActiveCell.Offset(RowOffset:=-1, ColumnOffset:=2).Select
ActiveSheet.Paste
Range("A1").Select
For Each cell In ws.Columns(1).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
Range(Selection, Selection.End(xlToRight)).Delete

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about
VBA Code:
Sub aquelious()
    Dim Cl As Range, Rng As Range
    
    For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlBlanks)
        Range(Cl.Offset(, 1), Cl.Offset(, 1).End(xlToRight)).Copy Cl.Offset(-1, 2)
        If Rng Is Nothing Then Set Rng = Cl Else Set Rng = Union(Rng, Cl)
    Next Cl
    If Not Rng Is Nothing Then Rng.EntireRow.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

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