PasteSpecial

csand

New Member
Joined
Jul 21, 2009
Messages
9
I'm currently setting up a macro that will input a vlookup from another workbook into a sheet, and then copy and paste just the value into another sheet in the first workbook.

Code:
Sheets("CopyPaste").Select
 
Worksheets("CopyPaste").Cells(9 + (nRow - 9), 17).Select
 
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-4],[VendorQuoteData.xls] Quotes!C1:C5,5)"
 
Worksheets("CopyPaste").Cells(9 + (nRow - 9), 17).Select
 
Range(ActiveCell).Copy
 
Sheets("Sheet").Select
 
Worksheets("Sheet").Cells((1 + (nRow - 9)), 27).Select
 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Everything works except for:

Code:
Range(ActiveCell).Copy

When I input the actual cell like "A2" it works fine, but this code sequence works in a loop with variables that change the row (nRow).

Any suggestions? Thank you.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
activecell is already a range, not an address, so

Range(ActiveCell).Copy

should be

ActiveCell.Copy

HTH
 
Upvote 0
Hi Weaver,

Thanks for the tip.

It turns out the problem is actually with where I select the cell to paste the value to.

Code:
ActiveCell.Select
 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

When I use the above code it works, but displays the values in one column too early.

End code that works is:

Code:
Sheets("CopyPaste").Select
Worksheets("CopyPaste").Cells(9 + (nRow - 9), 17).Select
 
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-4],[VendorQuoteData.xls]Quotes!C1:C5,5)"
 
Worksheets("CopyPaste").Cells(9 + (nRow - 9), 17).Select
ActiveCell.Copy
Sheets("Sheet").Select
ActiveCell.Offset(0, 1).Select
 
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
Upvote 0
I know it's not what you asked, but you don't need all the 'select' stuff, and often getting rid of it can make the code easier to follow, for instance:

Code:
Worksheets("CopyPaste").Cells(9 + (nRow - 9), 17).FormulaR1C1 = "=VLOOKUP(RC[-4],[VendorQuoteData.xls]Quotes!C1:C5,5)"
 
Worksheets("CopyPaste").Cells(9 + (nRow - 9), 17).Copy
Sheets("Sheet").Offset(0, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Should do the same job.
 
Upvote 0

Forum statistics

Threads
1,215,329
Messages
6,124,301
Members
449,149
Latest member
mwdbActuary

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