Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Jim Cone - Portland, Oregon USA - December 2008
'Adds 1 to the right most number in the cell.
Dim N As Long
Dim strOldText As String
With Worksheets("Sheet1").Range("G3")
If Not Right$(.Value, 1) Like "#" Then
MsgBox "Bad Entry"
Cancel = True
Else
strOldText = " " & .Value
For N = Len(strOldText) - 1 To 1 Step -1
If Not Mid$(strOldText, N, 1) Like "#" Then
.Value = LTrim(Left$(strOldText, N)) & _
CDbl(Right$(strOldText, Len(strOldText) - N)) + 1
Exit For
End If
Next
End If
End With
'for testing
'Cancel = True
End Sub
--
Jim Cone
Portland, Oregon USA
(thanks in advance is no thanks)
<Andre Laurence>
wrote in message
Hello,
I am sorry to ressurect an old issue, but I was wondering if someone could tell me if the following is possible?
I have used :
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
With Worksheets("Sheet1").Range("G3")
..Value = .Value + 1
End With
End Sub
With great success and would like to thank everyone in this thread, but I would like to know if there is a way to do this if the
cell value is not only a number (ie instead of just 12080250, IS12080250). The above code is great, but issues a Runtime error 13 if
there are any letters in the cell value.
Thank you in advance.