VBA - Copy/Paste range of selected rows

PaulMacF

New Member
Joined
Mar 6, 2023
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm using the following code to copy a range of selected rows (see pic) to another another worksheet, in another workbook (appended to the bottom of that worksheet).
Unfortunately this code is only pasting the first row of the selected range, not the entire selected block of rows. Would appreciate a fix please.

VBA Code:
Sub dagym()
'
' dagym Macro
'

'
   
ActiveCell.EntireRow.Select
Selection.Copy
Windows("Timeform Results for SQL Spreads.xlsx").Activate
Sheets("TF Results Sheet").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

End Sub
 

Attachments

  • mexcel3.PNG
    mexcel3.PNG
    165.2 KB · Views: 19

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
If you have already selected the rows you want to copy before running the code, then get rid of this line of code:
Excel Formula:
ActiveCell.EntireRow.Select
so you are just left with:
VBA Code:
Sub dagym()
'
' dagym Macro
'

Selection.Copy
Windows("Timeform Results for SQL Spreads.xlsx").Activate
Sheets("TF Results Sheet").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues

End Sub
 
Upvote 0
Solution
Hi Joe,

Have tried that. It's still just pasting the first selected row to the other sheet, instead of the entire block of rows.
 
Upvote 0
Hi again,

Okay I have sorted it out now, thanks very much, Joe
 
Upvote 0
You are welcome.

The key is "Selection" just uses whatever range you have pre-selected when you run the VBA code.
If you use "ActiveCell.EntireRow.Select", it will only run on the first row you have in your selected range, as you are changing the size of range (note that "ActiveCell" is always just one single cell, namely the first cell in your selected range).
 
Upvote 0

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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