View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ellis_x ellis_x is offline
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