Paste Data Below last row

karl_learnvba

New Member
Joined
Oct 10, 2019
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have data in 1 row that I would like ot create a table from.
The final table will be approx 9 cells wide.
If I were cutting and pasting the data manually I would :-
1) Select all items in the row from active cell to the far right (ativecell is L8 in the attached screenshot)
2) Cut
3) Paste below previous data

I got this far before running out of ideas I am seing an error in the pasting function towards the end
Can somebody please help ? Thanks in advance ! :)

Sub Macro1()

Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

' Cut & paste the Data
Dim cutRange As Range
Set cutRange = ws.Range(ActiveCell, ActiveCell.End(xlToRight))
cutRange.Cut
ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

End Sub
 

Attachments

  • Excel VBA Help.jpg
    Excel VBA Help.jpg
    143.2 KB · Views: 14

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try this.

VBA Code:
Sub Macro1()
    Dim ws As Worksheet
    Dim LastRow As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    
    ' Cut & paste the Data
    Dim cutRange As Range
    With ws
        Set cutRange = .Range(ActiveCell, .Cells(ActiveCell.Row, .Columns.Count).End(xlToLeft))
        LastRow = .Cells(.Rows.Count, ActiveCell.Column).End(xlUp).Row
        cutRange.Cut .Cells(LastRow + 1, ActiveCell.Column)
    End With
End Sub
 
Upvote 0
Try this.

VBA Code:
Sub Macro1()
    Dim ws As Worksheet
    Dim LastRow As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")
   
    ' Cut & paste the Data
    Dim cutRange As Range
    With ws
        Set cutRange = .Range(ActiveCell, .Cells(ActiveCell.Row, .Columns.Count).End(xlToLeft))
        LastRow = .Cells(.Rows.Count, ActiveCell.Column).End(xlUp).Row
        cutRange.Cut .Cells(LastRow + 1, ActiveCell.Column)
    End With
End Sub

Hi rlv01 - Thank you so much for spending time and sending this over.

An additional question:-

The procedure as above does select all the data, and it pastes it 1 row down.
What would I need to change to ensure that it pastes the data into the next empty row bottom of column A (Pic attached)

Thankyou!
 

Attachments

  • VBA1.png
    VBA1.png
    16 KB · Views: 10
Upvote 0
The procedure as above does select all the data, and it pastes it 1 row down.
What would I need to change to ensure that it pastes the data into the next empty row bottom of column A (Pic attached)

Just to be clear, "Paste below the previous data" means to me that that if the active cell is L8, then the data gets pasted to L9. Changing the paste location to column A is easy enough:
VBA Code:
Sub Macro1()
    Dim ws As Worksheet
    Dim LastRow As Long
    Set ws = ThisWorkbook.Worksheets("Sheet1")
  
    ' Cut & paste the Data
    Dim cutRange As Range
    With ws
        Set cutRange = .Range(ActiveCell, .Cells(ActiveCell.Row, .Columns.Count).End(xlToLeft))
        LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        cutRange.Cut .Cells(LastRow + 1, 1)
    End With
End Sub

But that also has the potential to seriously mess up your column organization depending on where the ActiveCell is at the time you run the macro.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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