ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Formula to add a number (https://www.excelbanter.com/excel-programming/404076-formula-add-number.html)

Debbie

Formula to add a number
 
Can someone give me a formula so that I can have a number added automatically
to a cell each time I open a report.

The number is 10-200-1 and each time I open the report I want it to
automatically populate the fiield with the next number 10-200-2, 10-200-3 and
so on.

Thanks in advavnce for your help,
Deborah

Mike H

Formula to add a number
 
When you say open a report I have assumed you mean open a workbook if so try
this

Private Sub Workbook_Open()
Sheets("Sheet1").Select 'Change to suit
oldnum = Left(Range("A1").Value, 7)
x = 1 + Val(Right(Range("A1").Value, Len(Range("A1").Value) - 7))
Range("A1").Value = oldnum & x
End Sub


Mike

"Debbie" wrote:

Can someone give me a formula so that I can have a number added automatically
to a cell each time I open a report.

The number is 10-200-1 and each time I open the report I want it to
automatically populate the fiield with the next number 10-200-2, 10-200-3 and
so on.

Thanks in advavnce for your help,
Deborah


Vergel Adriano

Formula to add a number
 
By "open the report" , do you mean open the workbook? If so, and assuming
that the number is in Sheet1!A1 do the following.

1. Enter the initial number in the cell as a number value (no dashes) and
give it a custom format of "00-000-00".

2. Then put this code in the ThisWorkbook code module:

Private Sub Workbook_Open()
With Sheet1.Range("A1")
.Value = .Value + 1
End With
End Sub


--
Hope that helps.

Vergel Adriano


"Debbie" wrote:

Can someone give me a formula so that I can have a number added automatically
to a cell each time I open a report.

The number is 10-200-1 and each time I open the report I want it to
automatically populate the fiield with the next number 10-200-2, 10-200-3 and
so on.

Thanks in advavnce for your help,
Deborah



All times are GMT +1. The time now is 10:23 AM.

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