Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Displaying results of loop in cells

I have very little experience with VBA in Excel and I'm trying to do a
Monte Carlo simulation. I have the following:


For x = 1 To 10000
Calculate
Range("D2").Select
Selection.Copy
Range("D6").Select
Selection.PasteSpecial Paste:=xlPasteValues
Next x

D2 is the cell where the result from another worksheet is displayed.
This result is derived from some random variables, and after each
calculation the result is different.

D6 is the first cell I want the result from D2 to be copied after the
first calculation, and D7 the result after the second calculation, etc.
etc.

If I change the 5th line with:

Range("D6:D10005").Select

I get the same result 10000 times, and not 10000 different results as I
want. I probably need to use the ARRAY function, but I have no idea how
to use this.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Displaying results of loop in cells

Here is what you want... Based on what you want I hope I am not helping you
cheat on your homework. It sounds like a lot of the assignments I got in
school... :)

Sub test()
Dim x As Long
Dim rngPaste As Range

Set rngPaste = Range("D6")

For x = 1 To 10000
Calculate
Range("D2").Copy
rngPaste.PasteSpecial Paste:=xlPasteValues
Set rngPaste = rngPaste.Offset(1, 0)
Next x

End Sub

HTH

" wrote:

I have very little experience with VBA in Excel and I'm trying to do a
Monte Carlo simulation. I have the following:


For x = 1 To 10000
Calculate
Range("D2").Select
Selection.Copy
Range("D6").Select
Selection.PasteSpecial Paste:=xlPasteValues
Next x

D2 is the cell where the result from another worksheet is displayed.
This result is derived from some random variables, and after each
calculation the result is different.

D6 is the first cell I want the result from D2 to be copied after the
first calculation, and D7 the result after the second calculation, etc.
etc.

If I change the 5th line with:

Range("D6:D10005").Select

I get the same result 10000 times, and not 10000 different results as I
want. I probably need to use the ARRAY function, but I have no idea how
to use this.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Displaying results of loop in cells

Thanks, it works, great

And about homework, I'm past that age. I wish I had assignments like
this on my school, it would have saved me a lot of time with the things
I want to do with Excel right now.

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
IF formula results not displaying JC Excel Worksheet Functions 1 May 29th 08 07:09 PM
Displaying how many results in a vlookup Danhalawi Excel Discussion (Misc queries) 1 November 16th 06 10:47 AM
Displaying formula rather than results... RUSH2CROCHET Excel Discussion (Misc queries) 3 April 10th 06 05:21 PM
functions are not displaying the results [email protected] Excel Worksheet Functions 1 February 16th 06 01:27 PM
Excel VBA - Cells Counting using VBA codes and displaying results in msg box wuming[_7_] Excel Programming 6 July 9th 04 03:18 AM


All times are GMT +1. The time now is 01:36 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"