VB Sum n+1

  • Thread starter Thread starter herve
  • Start date Start date
H

herve

Hello all.
could someone help me to do the following in a Macro.

In cell A1, I have Number "1"

I want to have :
A2 = A1 + 1
A3 = A2 + 1
A4 = A3 + 1
.....
Axx = Axx-1 + 1

Thanks in advance

Herve
 
For i = 2 To n
Cells(i,"A").Formula = "=A" & i-1
Next i

but it is not clear how to determine what n is, or how to calculate it (the
xx in yhour example).

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
will this do?

Sub addone()
For i = 1 To 4
Cells(i, 1) = i
Next
End Sub
 
Hello Herve,

Add a VBA project module and past this code into it.

EXAMPLE:
A1 = 3
A2 Formula is "= IncrementCell()"
A2 Result is 4


Code:
--------------------

Function IncrementCell() As Long

Dim X

With ActiveCell
If .Column = 1 Then Exit Function
X = .Offset(0, -1).Value + 1
End With

IncLeftCell = X

End Function
 
Hello Herve,

This macro allows you to select the cell you want. You can also dran
and fill your range with this formula. When the value in A1 changes, s
do all the dependent cells. Copy this macro into a VBA project module
To use it see the example.

EXAMPLE
A1 = 10
A2 = Increment(A1)
A3 = Increment(A2)
A4 = Increment(A3)

RESULTS
A1 = 10
A2 = 11
A3 = 12
A4 = 13

Macor Code

Code
-------------------
Function Increment(Cell As Excel.Range) As Long

Application.Volatile

Dim X

On Error Resume Next

X = Cell.Value + 1
Increment = X

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top