Mapping this Excel Formula to VBA

winneker

New Member
Joined
Jan 10, 2013
Messages
10
I currently have 28 distribution tables on 28 different worksheets in the same workbook. Im trying to get the following formula into my VBA code on the 29th (summary) worksheet - either into one cell that i can then fill across over a variable amount of months, or entered into that variable amount of cells (months) by column all at the same time, (using With... RANGE.RESIZE) whichever is easier and doable.

Essentially, the user of this workbook will look at the 28 pictoral graphs that accompany the 28 different distributions, they will select the one that most appropriately depicts the curve that their cost profile will follow, and based on the amount of months for their effort, the formula will distribute a variable Total Cost value by month among the variable amount of months. This formula was successful when pasted into each cell in excel, but i'd like to update the workbook for the task to be done with VBA.

=$C29*VLOOKUP($B29,INDIRECT("curve"&$D29,1),E$28+1,FALSE)

Where:
C29 is the total cost variable that i am distributing among the variable months
B29 is the amount of variable months
D29 is my indirect reference for the variable curve selected (between 1 and 28 options)
E28 is equal to 1 --> AN28 is equal to 36 representing the max amount of months the distribution curves will return a value for before summing to 1.0 in total

Again, once entered into the first cell, i would need to be able to fill right by 'x' amount of variable months and the column returned by the lookup would have to start in column 2 (E28+1) and work right to grow to a maximum of 36 months (37th column) which is as much as my tables will allow for.

-VBA newbie
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi winneker

I put your formula into a cell then recorded a macro, I entered the cell and pressed enter and then saved the macro

This is the result of the recording if this helps get you started

ActiveCell.FormulaR1C1 = _
"=R[11]C3*VLOOKUP(R[11]C2,INDIRECT(""curve""&R[11]C4,1),R28C[1]+1,FALSE)"
Range("D19").Select

All the best

Kevin
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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