hi experts![]()
last time you gave me this code for string increment
AI/WE/23--+1 increment--->AI/WE/24
but when i passed
AI/WE/001--+1 increment--->AI/WE/2
i required
AI/WE/002
plz help me ,what chang i make this function
thanks in advance![]()
Public Function IncrementString(ByVal sTxt As String, ByVal nIncrement As
Long) As String
Dim sParts() As String
Dim nUpperIdx As Long
'Split the string into different parts, use / as the delimiter
sParts = Split(sTxt, "/")
'the part to increment is the last number
nUpperIdx = UBound(sParts)
'Check that this part is numeric
If IsNumeric(sParts(nUpperIdx)) Then
'increment this part with nIncrement
sParts(nUpperIdx) = CStr(CLng(sParts(nUpperIdx)) + nIncrement)
End If
'Join the parts again and return the new string
IncrementString = Join(sParts, "/")
End Function




Reply With Quote