Efficiency of macro Execution

KerryFSA

New Member
Joined
Dec 5, 2018
Messages
49
In a spreadsheet, I have 5 columns of data (numbers or text) that I wish to copy to 5 other columns by using a macro.
There are at least 2 ways to do this:

1. use a loop, changing the column names/numbers by using a variable to identify the columns.
Then carry out the copy/paste functions each time through the loop.
i.e. one set of statements looped thru 5 times. OR

2. simply repeat statements which identify the columns explicitly, followed by the copy/paste functions.
i.e. 5 sets of explicit statements with no loops.

Method 2 is certainly easier to set up, since the variable in method 1 doesn't have to be programmed.
Which is the more efficient code? Or is there any even better way?

Thanks.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You haven't really detailed the 5 columns of data, but why not simply copy / paste the activesheet.UsedRange
OR
Set the area required to copy and paste as a block
 
Last edited:
Upvote 0
Thanks Michael,
The data in question is not in contiguous columns, which I should have mentioned.
In another transfer, I copy an entire 200x100 block of contiguous rows and columns and paste to a different workbook.
That works just fine. So, I'm not having trouble doing it; the question is somewhat theoretical, with broader practical application.
Is it faster to use a loop, or simply repeat the code as often as necessary?

Perhaps with a relatively small number of cells (200 per column) there is no practical difference.

Kerry
 
Last edited:
Upvote 0
If the columns are in a set sequence, ie, every 2nd or every 3rd, etc, you could use a loop
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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