View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Increment value in a Formula

Looking at your before and after examples I don't see any column changes.

H and J are consistent.

Only row increments of 12 as if you are copying down a single column.

Is that a typo or?

If you are copying down a column try this macro to increment the rows.

First remove the absolute reference $ signs from your first formula.

Sub Increment_Formula_Steps()
''copy a formula down with steps in cell references
''select range first with formula in active cell
Dim StepSize As Variant
Dim NumCopies As Integer
Dim Cell As Range
StepSize = InputBox("Step?") 'e.g., 12
If StepSize < "" Then
NumCopies = Selection.Rows.Count
Application.ScreenUpdating = False
For Each Cell In Selection.Columns(1).Cells
Cell.Copy Cell.Offset(StepSize)
Cell.Offset(StepSize).Cut Cell.Offset(1)
Next
End If
End Sub

If you want the absolute references add them after.

Sub Absolute()
Dim Cell As Range
For Each Cell In Selection
If Cell.HasFormula Then
Cell.Formula = Application.ConvertFormula _
(Cell.Formula, xlA1, xlA1, xlAbsolute)
End If
Next
End Sub


Gord Dibben MS Excel MVP

On Wed, 14 Apr 2010 06:13:01 -0700, David Marr <David
wrote:

Hi,

I'm using Excel version 2003.

I have the following formula =IF(SUM('Section
3'!$H$1675:$J$1686)=0,"",SUM('Section 3'!$H$1675:$J$1686)) and would like to
increment the cell references by 12.

I was wondering if there is a way to do this using a bit of VBA code?

So the result i'm looking for after code run is =IF(SUM('Section
3'!$H$1687:$J$1698)=0,"",SUM('Section 3'!$H$1687:$J$1698)).

I will be running the formula along the columns so will need to increment
the formula by 12 for each new column.

Thanks
Dave