Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA "For Loop" Question


thanx in advance for any help on this issue. I'm not a programmer, so
the code I've provided is likely very inefficient. my question is as
follows. I do a great deal of "scenario" analysis. it would be
beneficial to be able to change the "strategy" and copy the relevant
results to a certain location without having to copy numerous lines of
code for each scenario I'm testing. an example is below.

I take a "strategy" called "equity" and subtract the base case from it,
subsequently storing the results. my base case "equity" is 1, all
others are triggered by the numbers 2 - 12 in this instance. my result
table is a series of columns with names that go from "Res_ED_60" to
"Res_ED_70" with only the last 2 digits changing. to help with this
making a bit more sense, the results are simply (Res)ult (E)quity
(D)etermination (60) % of equity. the results are always copied from
"Res_ED". it would seem to me that I can put this in some type of loop
where the only things changing are the "equity" scenario in line 2 of
the code, and the relevant result set name in line 22 of the code. in
the event the lines get word wrapped incorrectly, I copy/pasted the 2
lines I think are relevant immediately below.
---------------------------------
ActiveCell.FormulaR1C1 = "3"
Application.Goto Reference:="Res_ED_61"
---------------------------------

Application.Goto Reference:="equity"
ActiveCell.FormulaR1C1 = "3"
Calculate
Application.Goto Reference:="active_equity"
Selection.Copy
Application.Goto Reference:="base_equity"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.Goto Reference:="active_label"
Selection.Copy
Application.Goto Reference:="base_label"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.Goto Reference:="equity"
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "1"
' copies ED cumulative imbalance results to results table
Application.Goto Reference:="Res_ED"
Selection.Copy
Application.Goto Reference:="Res_ED_61"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

Thank you again for any help on this issue. I'm hoping it's a fairly
easy task.


--
wingfield
------------------------------------------------------------------------
wingfield's Profile: http://www.excelforum.com/member.php...o&userid=12968
View this thread: http://www.excelforum.com/showthread...hreadid=536477

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default VBA "For Loop" Question

It is almost impossible to read recorded code like that, so try this on

Sub TestLoop()
for i = 60 to 70
application.Goto Reference:=Range("Res_ED_" & i)
msgbox "Res_ED_" & i
Next
end Sub

--
Regards,
Tom Ogilvy


"wingfield" wrote:


thanx in advance for any help on this issue. I'm not a programmer, so
the code I've provided is likely very inefficient. my question is as
follows. I do a great deal of "scenario" analysis. it would be
beneficial to be able to change the "strategy" and copy the relevant
results to a certain location without having to copy numerous lines of
code for each scenario I'm testing. an example is below.

I take a "strategy" called "equity" and subtract the base case from it,
subsequently storing the results. my base case "equity" is 1, all
others are triggered by the numbers 2 - 12 in this instance. my result
table is a series of columns with names that go from "Res_ED_60" to
"Res_ED_70" with only the last 2 digits changing. to help with this
making a bit more sense, the results are simply (Res)ult (E)quity
(D)etermination (60) % of equity. the results are always copied from
"Res_ED". it would seem to me that I can put this in some type of loop
where the only things changing are the "equity" scenario in line 2 of
the code, and the relevant result set name in line 22 of the code. in
the event the lines get word wrapped incorrectly, I copy/pasted the 2
lines I think are relevant immediately below.
---------------------------------
ActiveCell.FormulaR1C1 = "3"
Application.Goto Reference:="Res_ED_61"
---------------------------------

Application.Goto Reference:="equity"
ActiveCell.FormulaR1C1 = "3"
Calculate
Application.Goto Reference:="active_equity"
Selection.Copy
Application.Goto Reference:="base_equity"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.Goto Reference:="active_label"
Selection.Copy
Application.Goto Reference:="base_label"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.Goto Reference:="equity"
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "1"
' copies ED cumulative imbalance results to results table
Application.Goto Reference:="Res_ED"
Selection.Copy
Application.Goto Reference:="Res_ED_61"
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

Thank you again for any help on this issue. I'm hoping it's a fairly
easy task.


--
wingfield
------------------------------------------------------------------------
wingfield's Profile: http://www.excelforum.com/member.php...o&userid=12968
View this thread: http://www.excelforum.com/showthread...hreadid=536477


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I make a "tab name" the "chart title"? (question on this) [email protected] Charts and Charting in Excel 2 April 15th 09 06:26 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
"Disk is Full" add-on question to "Can't reset last cell" post tod [email protected] Excel Discussion (Misc queries) 0 January 22nd 07 02:32 AM
"Loop until" syntax question Fastbike[_5_] Excel Programming 4 September 3rd 05 03:16 PM
LOOP BETWEEN "FRONT" AND "END" SHEETS? ewan7279 Excel Programming 7 March 17th 05 03:11 PM


All times are GMT +1. The time now is 08:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"