Problem using variable in macro instead of copy/paste

moradisndat

New Member
Joined
Feb 19, 2021
Messages
15
Office Version
  1. 2007
Platform
  1. Windows
Trying to speed up macro. Need to copy a range of 4 columns and 25k rows from one sheet to another. Sheets are named on tabs. I declared variables as public at top for use by more than 1 sub. The problem is that only 1 cell is copied over.

This is what I have:

Set ws = ThisWorkbook.Sheets("Import")
Set wsNew = ThisWorkbook.Sheets("PSI")
Set rng = ws.Range("A1").CurrentRegion

'I tried both of the following:

wsNew.Range("A50") = rng.Value

wsNew.Range("A50").CurrentRegion = rng.Value

I figured the 2nd statement wouldn't work because it is a blank sheet.
Also, I need the numerical formats copied with the values.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,436
Try this...

VBA Code:
Set ws = ThisWorkbook.Sheets("Import")
Set wsNew = ThisWorkbook.Sheets("PSI")

ws.Range("A1").CurrentRegion.Copy
wsNew.Range("A50").PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
 
Solution

moradisndat

New Member
Joined
Feb 19, 2021
Messages
15
Office Version
  1. 2007
Platform
  1. Windows
Ok, I was trying to speed up code and read that copying and pasting should be avoided. But yes, your suggestion works. Thanks.
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,436
Using one copy/pastespecial isn't so bad.

The range2.Value = range1.Value method is faster but doesn't paste formats.
 

Forum statistics

Threads
1,147,747
Messages
5,742,960
Members
423,767
Latest member
dafydd_jwc

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
Top