Reduce number of function calls

mookyon

New Member
Joined
Dec 23, 2021
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Hi Everybody,



1) I am trying to reduce the number of functions calls in a loop (from 4 to one);

2) If possible, I also wish to find an alternative to “Application.Index” calls. Please advise.

Please look at the following --
(In short: we are transposing a vertical worksheet region into a four-consecutive-columns in a certain row of a VBA two-dimentional variant array)

Excel Formula:
' STORE worksheet's four results into vba array: varTests

varTests(t, 2) = Application.Index(wrkshtMAIN.Range("rgn?RunScore"), 1, 1)

varTests(t, 3) = Application.Index(wrkshtMAIN.Range("rgn?RunScore"), 2, 1)

varTests(t, 4) = Application.Index(wrkshtMAIN.Range("rgn?RunScore"), 3, 1)

varTests(t, 5) = Application.Index(wrkshtMAIN.Range("rgn?RunScore"), 4, 1)



I wish to replace these four calls with a more efficient code (maybe executing one call instead of four).

I’ve tried placing “Array(1,2,3,4)” at the row index of Application.Index but failed (probably did it wrong).

I am not experienced in VBA. I hope one of the members will be able to provide a hint.



1000 THX
 
(In short: we are transposing a vertical worksheet region into a four-consecutive-columns in a certain row of a VBA two-dimentional variant array)
I missed this earlier. Please do not write in such small font size unless there is a particular reason to do so.

If varTests is dimed as, say, (1 to 10, 1 to 5) then as far as I am aware you cannot read values into, say varTests(3,2), varTests(3,3), varTests(3,4), varTests(3,5) other than either individually as you originally showed or individually via a loop as already suggested.
 
Upvote 0
Solution

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,215,633
Messages
6,125,928
Members
449,274
Latest member
mrcsbenson

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