Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Incremental filling of cells

I am having difficulty with VBA programming. I am writing a short VBA
function that performs an incremental math procedure. I have no
problem getting the function to work and converge to the desired
answer. However, I can't seem to get the function to return data after
each increment so I can see how modifications
to the program alter the rate of convergence.

For example, an algortithm calculating the square root of a number.
The loop is below:

Do Until Err < 0.000001
X = Num / Estimate
Err = Abs(Estimate - X)

'I need to return Estimate, Err, and iCounter for
'each iteration. For iteration 1, the values should
'go to cells [C1.E1]; iteration 2 to [C2.E2], and so on

Estimate = (X + Estimate) / 2
iCounter = iCounter + 1
Loop

Any hints/advice/help would be most gratefuly appreciated.

MthNrd


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Incremental filling of cells



Do Until Err < 0.000001
X = Num / Estimate
Err = Abs(Estimate - X)

Cells(iCounter,"C").Value = Estimate
Cells(iCounter,"D").Value = Err
Cells(iCounter,"E").Value = iCounter

Estimate = (X + Estimate) / 2
iCounter = iCounter + 1
Loop


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"mthnrd " wrote in message
...
I am having difficulty with VBA programming. I am writing a short VBA
function that performs an incremental math procedure. I have no
problem getting the function to work and converge to the desired
answer. However, I can't seem to get the function to return data after
each increment so I can see how modifications
to the program alter the rate of convergence.

For example, an algortithm calculating the square root of a number.
The loop is below:

Do Until Err < 0.000001
X = Num / Estimate
Err = Abs(Estimate - X)

'I need to return Estimate, Err, and iCounter for
'each iteration. For iteration 1, the values should
'go to cells [C1.E1]; iteration 2 to [C2.E2], and so on

Estimate = (X + Estimate) / 2
iCounter = iCounter + 1
Loop

Any hints/advice/help would be most gratefuly appreciated.

MthNrd


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Incremental filling of cells

You've run aground on the Excel principle that a FUNCTION can only return
values to the cell it is called from - and no other cells.

A SUBROUTINE can write values to as many cells as you need.

HTH,

James Cox


"mthnrd " wrote in message
...
I am having difficulty with VBA programming. I am writing a short VBA
function that performs an incremental math procedure. I have no
problem getting the function to work and converge to the desired
answer. However, I can't seem to get the function to return data after
each increment so I can see how modifications
to the program alter the rate of convergence.

For example, an algortithm calculating the square root of a number.
The loop is below:

Do Until Err < 0.000001
X = Num / Estimate
Err = Abs(Estimate - X)

'I need to return Estimate, Err, and iCounter for
'each iteration. For iteration 1, the values should
'go to cells [C1.E1]; iteration 2 to [C2.E2], and so on

Estimate = (X + Estimate) / 2
iCounter = iCounter + 1
Loop

Any hints/advice/help would be most gratefuly appreciated.

MthNrd


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Incremental filling of cells

Bob,

Thanks that helped...I also found looking through other posts the
following code which appears to do the same:

Range("C" & iCounter) = Estimate
Range("D" & iCounter) = Err
Range("E" & iCounter) = iCounter

What is the difference?

Thanks again,

MthNrd


---
Message posted from http://www.ExcelForum.com/

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
Filling in blank cells with information from cells above it tracytracy123 Excel Discussion (Misc queries) 1 June 22nd 09 11:04 PM
Filling cells FSt1 Excel Discussion (Misc queries) 1 January 10th 08 03:39 AM
filling cells widman Excel Discussion (Misc queries) 0 November 29th 06 07:29 PM
filling cells Art Excel Discussion (Misc queries) 0 November 29th 06 06:35 PM
Linking incremental cells from another worksheet Aaron Daniels Excel Discussion (Misc queries) 2 November 18th 05 12:16 AM


All times are GMT +1. The time now is 03:42 PM.

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

About Us

"It's about Microsoft Excel"