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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,437
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,437
Using one copy/pastespecial isn't so bad.

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

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,570
Messages
5,770,913
Members
425,652
Latest member
Pemby

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