Learn Microsoft Excel Training from the Best Tutors
Search in
To modify only the last three digits of a serial number string in Excel VBA, extract the last three characters, convert them to a number, add your desired value while ensuring it stays within a three-digit range, then update the original string with the modified digits. Here's a concise code snippet:
Sub IncreaseLastThreeDigits()
Dim serialNumber As String
serialNumber = "ABC123456" ' Replace with your serial number
Dim lastDigits As Long
lastDigits = (CLng(Right(serialNumber, 3)) + 100) Mod 1000 ' Increase by 100 (for example)
serialNumber = Left(serialNumber, Len(serialNumber) - 3) & Format(lastDigits, "000") ' Update serial number
MsgBox "Updated Serial Number: " & serialNumber ' Display updated serial number
End Sub
Replace "ABC123456"
with your actual serial number string and adjust the + 100
part to increase the last three digits by your desired value. Execute this code in Excel VBA to view the updated serial number in a message box.
Sub IncreaseLastThreeDigits()
Dim originalString As String
Dim prefix As String
Dim lastThreeDigits As String
Dim newLastThreeDigits As String
' Example serial number string
originalString = "ABC123456"
' Extract prefix and last three digits
prefix = Left(originalString, Len(originalString) - 3)
lastThreeDigits = Right(originalString, 3)
' Increase the last three digits
newLastThreeDigits = Format(Val(lastThreeDigits) + 1, "000")
' Concatenate the prefix and the new last three digits
Dim newSerialNumber As String
newSerialNumber = prefix & newLastThreeDigits
' Display the result
MsgBox "Original Serial Number: " & originalString & vbCrLf & "New Serial Number: " & newSerialNumber
End Sub
View 1 more Answers
Related Questions
Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com
Ask a QuestionRecommended Articles
Why Should you Learn Microsoft Office
Microsoft Office is a very popular tool amongst students and C-Suite. Today, approximately 1.2 billion people across 140 countries use the office programme. It is used at home, schools and offices on a daily basis for organizing, handling and presenting data and information. Microsoft Office Suite offers programs that can...
Make a Career as a BPO Professional
Business Process outsourcing (BPO) services can be considered as a kind of outsourcing which involves subletting of specific functions associated with any business to a third party service provider. BPO is usually administered as a cost-saving procedure for functions which an organization needs but does not rely upon to...
What is Applications Engineering all about?
Applications engineering is a hot trend in the current IT market. An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...
Top 5 Skills Every Software Developer Must have
Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today. In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...
Looking for Microsoft Excel Training classes?
Learn from the Best Tutors on UrbanPro
Are you a Tutor or Training Institute?
Join UrbanPro Today to find students near youThe best tutors for Microsoft Excel Training Classes are on UrbanPro
The best Tutors for Microsoft Excel Training Classes are on UrbanPro