Copy Paste different cells to next empty row

Steves73

Board Regular
Joined
Oct 19, 2016
Messages
173
Office Version
  1. 365
Platform
  1. Windows
Hi All

I am looking for a simple code that copies different cells on sheet 1 to next empty row on sheet 2

Example - Copy cells Sheet1 (A4, B7, D11, J23)

Paste to Sheet2 next empty row - Cells would copy to Row 2 - A2,B2,C2,D2

Then I run the code again it would copy the same cells on Sheet 1 to Sheet 2 Row 3 - A3,B3,C3,D3

And so on
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
VBA Code:
Sub Test()
Dim a
    a = Array(Range("A4"), Range("B7"), Range("D11"), Range("J23"))
    With Sheets("Sheet2")
        .Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).Resize(, UBound(a) + 1) = a
    End With
End Sub
 
Upvote 0
Solution
code that copies different cells on sheet 1 to next empty row on sheet 2
Assuming that means you want any formulas, formatting etc in those cells copied, you could try ..

VBA Code:
Sub Test1()
  Dim ws2 As Worksheet
  Dim nr As Long
 
  Set ws2 = Sheets("Sheet2")
  nr = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
  With Sheets("Sheet1")
    .Range("A4").Copy ws2.Cells(nr, 1)
    .Range("B7").Copy ws2.Cells(nr, 2)
    .Range("D11").Copy ws2.Cells(nr, 3)
    .Range("J23").Copy ws2.Cells(nr, 4)
  End With
End Sub
 
Upvote 0
VBA Code:
Sub Test()
Dim a
    a = Array(Range("A4"), Range("B7"), Range("D11"), Range("J23"))
    With Sheets("Sheet2")
        .Range("A" & .Cells(Rows.Count, 1).End(xlUp).Row + 1).Resize(, UBound(a) + 1) = a
    End With
End Sub
Thanks mohadin, Works perfectly, Sorry about the delayed reply
 
Upvote 0
Assuming that means you want any formulas, formatting etc in those cells copied, you could try ..

VBA Code:
Sub Test1()
  Dim ws2 As Worksheet
  Dim nr As Long
 
  Set ws2 = Sheets("Sheet2")
  nr = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
  With Sheets("Sheet1")
    .Range("A4").Copy ws2.Cells(nr, 1)
    .Range("B7").Copy ws2.Cells(nr, 2)
    .Range("D11").Copy ws2.Cells(nr, 3)
    .Range("J23").Copy ws2.Cells(nr, 4)
  End With
End Sub
Hi Peter. Thank you, your code works just as well, Just not sure how to change the code to stop the formulas coming over, formatting yes, Formulas no. But I can play around with it
 
Upvote 0
Thanks mohadin, Works perfectly
Just a slight word of warning. Ii may not be possible for you but if Sheet1 is not the active sheet when that code is run, the results will not be correct.

not sure how to change the code to stop the formulas coming over,
Well you asked for copy. Generally when you copy, formulas are copied. ;)
However, if it is only values that you want then you can also do it with a one-liner like this.

VBA Code:
Sub Test2()
  Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(, 4).Value = Application.Index(Sheets("Sheet1").Range("A4,B7,D11,J23"), 1, 1, Array(1, 2, 3, 4))
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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