Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default 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
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
How do I view and edit the source code for a Chart in Excel 2003? EBB Charts and Charting in Excel 2 March 21st 07 08:16 PM
How do you link chart source data when you copy the chart? mamagirl Charts and Charting in Excel 1 December 8th 06 02:40 AM
Hard-code source data Melanie Martin Charts and Charting in Excel 5 December 29th 05 02:07 PM
Changing a chart source data in code. JimPNicholls Excel Programming 1 May 7th 04 03:57 PM
Source Data Code Cleanup Help John Michl[_2_] Excel Programming 2 August 18th 03 09:01 PM


All times are GMT +1. The time now is 11:09 AM.

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"