Macro to Move Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have data in Cols A to W from row 13 onwards (row 13 can sometimes be blank) on sheet PLAccounts

I need macro to move the data below A13 where there are blank rows and then data below the blank rows to the first row from A13 where there is no data

I tried to write code to do this, but cannot get it to works


Code:
 Sub MoveData()
    Dim lastRow As Long
    Dim i As Long
    Dim ws As Worksheet
    
    Set ws = ThisWorkbook.Sheets("PLAccounts")
    
    lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
    
    If lastRow > 13 Then
        For i = 23 To 1 Step -1 ' loop through columns W to A
            If i <> 13 Then ' skip column M
                ws.Range(ws.Cells(14, i), ws.Cells(lastRow, i)).Cut Destination:=ws.Cells(13, i)
            End If
        Next i
    End If
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I am confused what you are asking for so perhaps a before & after XL2BB example might be in order to show what your data looks like to start with and what it should look like afterwards.

It sounds like you want to remove the blank rows in the data between A13 & the start of your data below that, but you didn't say that.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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