View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Formula in a range which varies in size

How do you determine the range of rows?

Option Explicit
Sub testme()

Dim FirstRow As Long
Dim LastRow As Long

With Worksheets("sheet1")
FirstRow = 2 'headers in row 1 and row 2 starts the data
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

With .Range(.Cells(FirstRow, "Q"), .Cells(LastRow, "Q"))
.FormulaR1C1 = "=SUM(RC[-3]:RC[-2])"
'.Value = .Value
End With
End With

End Sub

This actually puts a formula in that range. If you want the value, then
uncomment that ".value = .value" line.

And I used column A to determine the last row to populate.

Alan M wrote:

Hi I need code to be able to scroll through the cells in a range of variable
size and add the values in the in columns N and O and place the result in
column Q for each row in the range. The number of rows varies each time.

Thanks


--

Dave Peterson