Help writing a loop within loop in VBA

pplstuff

Well-known Member
Joined
Mar 9, 2012
Messages
951
I have a workbook doing sensitivity analysis, which takes a long time to calculate. I'm hoping a macro can do it faster (currently, calculation takes a few hours).

Here's what I need:
-I have a worksheet Sens! and another Inputs!

-I need to enter values 180, 200, 220,..., 320 in Inputs!G4
-I need to enter values 0,1,2,3,...,16 in Inputs!G5
-I need to Copy DCF!C40 and paste it into a matrix that will be on the Sens! sheet (currently, there is no matrix).

The macro would say:
Inputs!g4 becomes 180
Inputs!g5 becomes 0
recalculate workbook
Copy DCF!C40
Paste into Sens!B2

Inputs!G5 becomes 1
Recalculate
Copy DCF!C40
Paste into Sens!C2

Inputs!G5 becomes 2
Recalulate
Copy DCF!C40
Paste into Sens!C3

Once Inputs!G5 = 16 has been calculated, change Inputs!G4 from 180 to 200 and repeat (but paste into B3).

If anyone could help with a marco for this processes I would really appreciate it! It's a loop within a loop, and I'm not sure how to do this (also not sure what the best type is: do for, do while, for, etc.)

Excel 2007
 
Last edited:
Hi pplstuff,

It looks like you're on your way. I don't know why your copy code doesn't work - it works on my machine.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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