ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   increment number by code (https://www.excelbanter.com/excel-programming/335290-increment-number-code.html)

nowfal[_22_]

increment number by code
 

hi,
I got a formula to increment the number ie. =OFFSET(A3,1,O)+1
but i am searching how to do by code so that no user can delete th
formula
recently i saw a code that is incrementing the number to the next line
what i am
looking for one number more than A4 . If A4 is 999 , A3 to show 1000

Below the code i saw in another thread, is it possible to alter th
code and use for me . Any help is highly appreciated.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim newval As Long
'test if its in the table
If Range("B1").End(xlDown).Address = Target.Address Then

If Target.Offset(0, -1).Value = "" Then

newval = Target.Offset(-1, -1).Value + 1

Do While WorksheetFunction.CountIf(Range("A:A"), newval) 0
newval = newval + 1
Loop

Target.Offset(0, -1).Value = newval

End If

End If

End Sub


thanks and regards
nowfa

--
nowfa
-----------------------------------------------------------------------
nowfal's Profile: http://www.excelforum.com/member.php...fo&userid=1000
View this thread: http://www.excelforum.com/showthread.php?threadid=38945



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

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