New poster to forum. Hope I am doing this correctly. Thanks for all the help you have been in the past without me posting!
I have a macro, inserted below, attributed to Harald Staff, that reads a text file for the last incremental number, and then fills B5 with the next number, and updates the text file. Works great, but it currently only fills one cell (B5).
I need it to fill all the empty rows down column B, and then save that last number. The number of rows that need to be numbered changes from use to use. There is always data in column A and column C. Column B is always empty before the macro runs.
I am afraid it is beyond me to get it to determine the last row (last data in Column A or C) and to get it to fill B5 down to the last row with an incremental number, starting at the saved number plus one, and then store the last number in the text file for future reference.
Thanks in advance for any help you can provide.
Bob
Here is the current code:
Sub Lead_Number()
'by Harald Staff
Dim ThisInvoice As Long
Dim ReadText As String
Dim StoreFile As String
StoreFile = "C:\Data\LeadNumberMaster.txt"
'replace with another path,
'network folder if multi-user
'read previous number:
If Dir(StoreFile) = "" Then 'not found
ThisInvoice = 1
Else
Open StoreFile For _
Input Access Read As #1
While Not EOF(1)
Line Input #1, ReadText
ThisInvoice = Val(ReadText)
Wend
Close #1
End If
ThisInvoice = ThisInvoice + 1
'Store this number:
Open StoreFile For _
Output Access Write As #1
Print #1, ThisInvoice
Close #1
With Range("B5") ' change to suit
.Value = ThisInvoice
End With
End Sub
You almost have the code tags correct
the last 1 needs to be [/code
Bookmarks