PDA

View Full Version : Pasting a selection of data



thespeculata
04-06-2011, 12:06 AM
I am struggling to find the code to paste data that has been selected.

Below is the code and am happy for comments

'Go to A1 and select all data
ActiveSheet.Range("A1").Select
ActiveSheet.Range(Selection, Selection.Columns(3)).EntireColumn.Select

'Copy selected cells
Selection.Copy

'Go to tab to paste data
Sheets("TB-" & Worksheets("Menu").Range("D12")).Select
ActiveSheet.Range("A4").Select
ActiveSheet.Selection.Paste

I have tried the following and others but not sure where I'm going wrong
1>
Selection.PasteSpecial Paste:=xlValues
2>
ActiveSheet.PasteSpecial xlPasteValues
3>
Set Worksheets("TB-" & Worksheets("Menu").Range("D12")) = ActiveSheet
ActiveSheet.Range("A4").PasteSpecial Paste:=xlPasteValues

Cheers

GTO
04-06-2011, 04:51 AM
Hi there,

I did not try your code, but at first blush, it appears that you are grabbing entire columns (that is, from the first row to the last) and trying to paste from row 4 and downward. If I didn't miss something, your paste runs out of room at the bottom.

shrivallabha
04-06-2011, 09:39 AM
You can post sample data alongwith expected results. This will help you get a good solution.

thespeculata
04-06-2011, 05:10 PM
Good point, I have changed the selection code to:

ActiveSheet.Range("A2:C3000").Select

'Copy selected cells
Selection.Copy

'Go to tab to paste data
Sheets("TB-" & Worksheets("Menu").Range("D12")).Select
Worksheets("TB-" & Worksheets("Menu").Range("D12")).Activate
Range("A4:C3002").Select
But I am still having an issue pasting, I keep getting a 400 error message??

Please help.

thespeculata
04-06-2011, 05:16 PM
Solved it

Sheets("TB-" & Worksheets("Menu").Range("D12")).Select
Worksheets("TB-" & Worksheets("Menu").Range("D12")).Activate
ActiveSheet.Range("A4:C3002").Select
Selection.PasteSpecial xlPasteValues
Thanks for your input GTO and Shrivallabha