LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - loop code problem

Hello,

I am a newb at VBA programming, but I am trying to get a loop code t
run. A simple example in below.


Code
-------------------

Sub Macro2()

' This loop runs until there is nothing in the next column

Range("D1").Select

Dim n As Variant

n = 1
Do
ActiveCell.FormulaR1C1 = "=Average(Cells(n, 1), Cells(n, 2))"
ActiveCell.Offset(0, 2).Select
n = n + 1
Loop Until IsEmpty(Cells(n, 1))

End Sub

-------------------


Hopefully someone here will be able to spot what is wrong with wha
I've done here and be kind enough to help.

What is posted here, just puts "=Average(Cells(n, 1), Cells(n, 2))
iin each of the cells - instead of calculating the number .

Using

Code
-------------------

ActiveCell.FormulaR1C1 = "=Average(Cells(n, 1).Value, Cells(n, 2).Value)"

-------------------

comes back with an error.

Cheers

Elli

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

 
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 to Loop some code Phil Osman Excel Discussion (Misc queries) 2 August 19th 05 11:14 AM
VB for excel, how do I loop through code steve hobden via OfficeKB.com Excel Discussion (Misc queries) 2 June 9th 05 01:59 PM
Excel VBA code required (for.......next loop) uplink600[_2_] Excel Programming 5 May 18th 04 10:08 AM
VBE code in a loop loloflores Excel Programming 0 April 30th 04 12:28 PM
Excel VBA - Help with a loop, compare, delete problem rippy Excel Programming 0 February 4th 04 03:38 PM


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