Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clumsy VBA Code for Chart Source Data from Loop
I have written VBA code for a Loop that generates 50 different outcomes by
changing the input variable to a formula (TotalPL). The module generates a 50 row list of the iteration of the variable stepping it up by 1 for each count. I then use the list to create a graph of the impact of each variable on the outcome. To do this I have written a copy and paste routine to capture the outcome for each iteration of the loop. It looks very inefficient, and takes a long time as the screen flashes from Worksheet1 to Worksheet2 and back for each cut and paste iteration. (the source data list ends up on Sheet1) I would much appreciate any suggestions to accomplish this more elegantly. As is evident I am an unskilled programmer! My code (based on John Walkenbach's book) is as follows: Sub GoodLoop3() StartVal = 1 TotalPL = Application.Sheets("Sheet2").Range("B32") NumToFill = Sheets("Sheet2").Range("E17") ' Following takes place on Sheet1 Range("B3").Value = StartVal For Cnt = 0 To NumToFill - 1 Range("B3").Offset(Cnt, 0).Value = StartVal + Cnt Range("B3").Offset(Cnt, 0).Copy Sheets("Sheet2").Select ' Range E12 is the input variable whcih needs 50 different values input into it Range("E12").Select Selection.PasteSpecial Paste:=xlValues Range("B32").Select ' Range B32 is the formula result which I would like to call TotalPL Selection.Copy Sheets("Sheet1").Select Range("B3").Offset(Cnt, 1).PasteSpecial Paste:=xlValues Application.CutCopyMode = False Range("B3").Offset(Cnt, -1).Select Next Cnt End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clumsy VBA Code for Chart Source Data from Loop
First to prevent the screen flashing and save time, after the first
line (sub...) type in Application.ScreenUpdating = False. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Clumsy VBA Code for Chart Source Data from Loop
Thank you Skiloa - that helped.
Any other suggestions welcomed "skiloa" wrote: First to prevent the screen flashing and save time, after the first line (sub...) type in Application.ScreenUpdating = False. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I view and edit the source code for a Chart in Excel 2003? | Charts and Charting in Excel | |||
How do you link chart source data when you copy the chart? | Charts and Charting in Excel | |||
Hard-code source data | Charts and Charting in Excel | |||
Changing a chart source data in code. | Excel Programming | |||
Source Data Code Cleanup Help | Excel Programming |