View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
David Marr[_2_] David Marr[_2_] is offline
external usenet poster
 
Posts: 2
Default Increment value in a Formula

Thanks for the reply but that doesn't seem to work.

I have the following code in another Excel file I have but i need to alter
it to ignore the Section 3 as it seems to increment that by 12.

Sub add125()
Dim rngToChange As Range
Dim iChar As Integer, iCount As Integer
Dim strOld As String, strNew As String, strNumb As String
Dim strChar As String
Set rngToChange = ActiveCell
strOld = rngToChange.Formula
strNew = ""
strNumb = ""
iCount = 0
For iChar = 1 To Len(strOld)
strChar = Mid(strOld, iChar, 1)
If IsNumeric(strChar) Then
strNumb = strNumb & strChar
Else
If strNumb < "" Then
iCount = iCount + 1
strNew = strNew & (strNumb + IIf(iCount = 3, 0, 132))
strNumb = ""
End If
strNew = strNew & strChar
End If
Next iChar
rngToChange.Formula = strNew
End Sub

Sub add12()
Dim rngToChange1 As Range
Dim iChar1 As Integer, iCount1 As Integer
Dim strOld1 As String, strNew1 As String, strNumb1 As String
Dim strChar1 As String
Set rngToChange1 = ActiveCell
strOld1 = rngToChange1.Formula
strNew1 = ""
strNumb1 = ""
iCount1 = 0
For iChar1 = 1 To Len(strOld1)
strChar1 = Mid(strOld1, iChar1, 1)
If IsNumeric(strChar1) Then
strNumb1 = strNumb1 & strChar1
Else
If strNumb1 < "" Then
iCount1 = iCount1 + 1
strNew1 = strNew1 & (strNumb1 + IIf(iCount1 = 3, 0, 12))
strNumb1 = ""
End If
strNew1 = strNew1 & strChar1
End If
Next iChar1
rngToChange1.Formula = strNew1
End Sub

Where am I going wrong?

cheers

Dave

"Bernard Liengme" wrote:

A VBA solution with zero's blanked out;
First cell used formula =Dozen(A1) to sum the first block
Drag this to the right to make =Dozen(B1) to sum next block
etc....

Function dozen(myblock)
whatblock = (myblock.Column - 1) * 12
mystart = 1675 + whatblock
firstcell = "H" & mystart
mylast = 1686 + whatblock
lastcell = "J" & mylast
myrange = "Section3!" & firstcell & ":" & lastcell
dozen = WorksheetFunction.Sum(Range(myrange))
If dozen = 0 Then dozen = ""
End Function

best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"David Marr" <David wrote in message
...
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


.