Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Formula in a range which varies in size


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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
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
Can a range be copied if it varies in size? TheMilkGuy Excel Discussion (Misc queries) 4 August 12th 09 10:05 PM
Setting a range that varies Stephen English Excel Programming 2 April 6th 09 08:43 PM
Sum of a range that varies Sebastien Excel Discussion (Misc queries) 1 February 19th 08 04:19 PM
Macro to find a range that varies. Paul Excel Programming 4 November 29th 05 11:38 AM
Insert SUM Formula using VBA (Range Varies) William Horton Excel Programming 6 August 8th 05 03:18 PM


All times are GMT +1. The time now is 11:04 PM.

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"