most efficient way of copying and paste a range as values VBA

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
782
Office Version
  1. 365
  2. 2010
right now im doing swtiching back and forth constantly...

Code:
'acct
Range("i2:i" & finalrow).Copy


Sheets("softek upload").Select


Range("a2").PasteSpecial xlPasteValues






'adp code
'


Sheets("index arb").Select


Range("a2:a" & finalrow).Copy
'


Sheets("softek upload").Select


Range("b2").PasteSpecial xlPasteValues


i originally ddid range("a2:a" & finalrow).copy sheets("softek upload").range("b2"), but this falls apart when the original data sheet has formulas...in the destination sheet, it gives me reference errors


so i need to paste as values
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try this:

Code:
Sub test()
  Dim lr As Long
  lr = Sheets("index arb").Range("A" & Rows.Count).End(xlUp).Row
  Sheets("softek upload").Range("B2").Resize(lr - 1).Value = Sheets("index arb").Range("A2:A" & lr).Value
End Sub
 
Upvote 0
Try:

Code:
Dim ws As Worksheet

Set ws = Sheets("softek upload")

With Sheets("index arb")
    ws.Range("a2:a" & finalrow).Value = .Range("i2:i" & finalrow).Value
    ws.Range("b2:b" & finalrow).Value = .Range("a2:a" & finalrow).Value
End With
 
Upvote 0
I think this should work:
Code:
Sheets("softek upload").Range("b2:b" & finalrow).Value = Range("a2:a" & finalrow).Value
 
Upvote 0
Hello daveyc18,

In VBA it is rare that you need to select an object before performing an action on it.

Code:
'acct - You may need to replace ActiveSheet with the Sheets("Sheet Name") 
Sheets("softek upload").Range("A2").Resize(finalrow - 1, 1).Value = ActiveSheet.Range("I2:I" & finalrow).Value




'adp code
Sheets("softek upload").Range("B2").Resize(finalrow - 1, 1).Value = Sheets("index arb").Range("A2:A" & finalrow).Value
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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