ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Sum n+1 (https://www.excelbanter.com/excel-programming/344689-vbulletin-sum-n-1-a.html)

herve[_13_]

VB Sum n+1
 

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


--
herve
------------------------------------------------------------------------
herve's Profile: http://www.excelforum.com/member.php...o&userid=27314
View this thread: http://www.excelforum.com/showthread...hreadid=482037


Bob Phillips[_6_]

VB Sum n+1
 

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)


"herve" wrote in
message ...

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


--
herve
------------------------------------------------------------------------
herve's Profile:

http://www.excelforum.com/member.php...o&userid=27314
View this thread: http://www.excelforum.com/showthread...hreadid=482037




Don Guillett[_4_]

VB Sum n+1
 
will this do?

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


--
Don Guillett
SalesAid Software

"herve" wrote in
message ...

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


--
herve
------------------------------------------------------------------------
herve's Profile:

http://www.excelforum.com/member.php...o&userid=27314
View this thread: http://www.excelforum.com/showthread...hreadid=482037




Leith Ross[_210_]

VB Sum n+1
 

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

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=482037


Leith Ross[_211_]

VB Sum n+1
 

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

-------------------

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48203


herve[_14_]

VB Sum n+1
 

Thanks all,
it works.

Bye


--
herve
------------------------------------------------------------------------
herve's Profile: http://www.excelforum.com/member.php...o&userid=27314
View this thread: http://www.excelforum.com/showthread...hreadid=482037



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com