Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2017, 01:50 AM
srinivasaru srinivasaru is offline Creating alphanumeric incremental serial numbers Windows 8 Creating alphanumeric incremental serial numbers Office 2013
Novice
Creating alphanumeric incremental serial numbers
 
Join Date: Mar 2017
Posts: 10
srinivasaru is on a distinguished road
Default Creating alphanumeric incremental serial numbers

Hi Excel Gurus,



I have a date field (dtDate) and a combobox field (cbxLocSName) (which will have a location short name) among various other fields in a data filling userform.
The format of the serial number is (Location short name + last 2 digits of the year + month + 3 digit serial number).

For ex.:

AAA1704001
AAA1704002
BBB1704001
BBB1704002

When a user changes the location short name or the date, then search the column "A" in the worksheet and find the last serial number for that particular combination of location short name, year and month
and increment it by 1 and show it another textbox (txtDocNo). So for LocSName AAA, the DocNo should show as AAA1704003

Also when the user selects a location short name for which there is no entry in the worksheet, then the DocNo should show as:

For ex.:

If the new location Short Name is CCC

Then the DocNo should show as CCC1704001

Any help on how to proceed with the above is much appreciated.

Expecting an early reply, thanks in advance.

Srinivas.
Reply With Quote
  #2  
Old 04-03-2017, 08:15 AM
srinivasaru srinivasaru is offline Creating alphanumeric incremental serial numbers Windows 8 Creating alphanumeric incremental serial numbers Office 2013
Novice
Creating alphanumeric incremental serial numbers
 
Join Date: Mar 2017
Posts: 10
srinivasaru is on a distinguished road
Default

Got it working by searching through the range with a string and adding an (*) at the end of the string.

Srinivas
Reply With Quote
  #3  
Old 04-03-2017, 10:52 AM
Logit Logit is offline Creating alphanumeric incremental serial numbers Windows 10 Creating alphanumeric incremental serial numbers Office 2007
Expert
 
Join Date: Jan 2017
Posts: 533
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Just read your postings.

Would you be so kind to post your code for review ?

Thank you.
Reply With Quote
  #4  
Old 04-03-2017, 11:23 AM
srinivasaru srinivasaru is offline Creating alphanumeric incremental serial numbers Windows 8 Creating alphanumeric incremental serial numbers Office 2013
Novice
Creating alphanumeric incremental serial numbers
 
Join Date: Mar 2017
Posts: 10
srinivasaru is on a distinguished road
Default

Yes for sure, below is my code

<Code>
Str = tRangeShort + Right(Year(dtDate.Value), 2) + Month(dtDate.Value)
txtDocNo.Text = GetIncrementalSerialNumber(NewRange, Str)

Private Function GetIncrementalSerialNumber(inRange As Range, sStr As String) As String
Dim StrSrch As String, tSerial As String, tNo As String
Dim tDigit As Integer, i As Integer
Dim tpRange As Range

StrSrch = sStr & "*" 'Concatenate an (*) at the end of the string
tSerial = ""
tNo = 0

For Each tpRange In inRange
If tpRange.Value Like StrSrch Then
tNo = tNo + 1 'Counter to find the number of exact matches
End If
Next tpRange
tNo = tNo + 1 'Adding 1 to total number of exact matches available

tDigit = 3 - Len(tNo) 'Find the length of the counter to prefix 0s
For i = 1 To tDigit
tSerial = "0" & tSerial 'Prefix 0s as required
Next i

GetIncrementalSerialNumber = sStr & tSerial & tNo 'Concatenate all
End Sub
<\Code>
Reply With Quote
  #5  
Old 04-03-2017, 11:26 AM
srinivasaru srinivasaru is offline Creating alphanumeric incremental serial numbers Windows 8 Creating alphanumeric incremental serial numbers Office 2013
Novice
Creating alphanumeric incremental serial numbers
 
Join Date: Mar 2017
Posts: 10
srinivasaru is on a distinguished road
Default

Sorry I don't know how to post the codes within a box in this site.
Reply With Quote
  #6  
Old 04-03-2017, 11:28 AM
srinivasaru srinivasaru is offline Creating alphanumeric incremental serial numbers Windows 8 Creating alphanumeric incremental serial numbers Office 2013
Novice
Creating alphanumeric incremental serial numbers
 
Join Date: Mar 2017
Posts: 10
srinivasaru is on a distinguished road
Default

and the last line of the code should be End Function and not End Sub.
Reply With Quote
  #7  
Old 04-03-2017, 11:38 AM
Logit Logit is offline Creating alphanumeric incremental serial numbers Windows 10 Creating alphanumeric incremental serial numbers Office 2007
Expert
 
Join Date: Jan 2017
Posts: 533
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Use HASH TAGS to embed code for display.

It will look like this when done accurately:

[ CODE]
your code
[ /CODE]

Thanks for the macro !
Reply With Quote
  #8  
Old 04-03-2017, 12:51 PM
srinivasaru srinivasaru is offline Creating alphanumeric incremental serial numbers Windows 8 Creating alphanumeric incremental serial numbers Office 2013
Novice
Creating alphanumeric incremental serial numbers
 
Join Date: Mar 2017
Posts: 10
srinivasaru is on a distinguished road
Default

Thanks Logit...
Reply With Quote
  #9  
Old 04-03-2017, 12:53 PM
srinivasaru srinivasaru is offline Creating alphanumeric incremental serial numbers Windows 8 Creating alphanumeric incremental serial numbers Office 2013
Novice
Creating alphanumeric incremental serial numbers
 
Join Date: Mar 2017
Posts: 10
srinivasaru is on a distinguished road
Default

how to make this thread solved....
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Excel have created a shop transfer note, these need to have individual rolling serial numbers nette74 Excel Programming 0 05-02-2015 02:48 AM
Creating alphanumeric incremental serial numbers incremental printing in ms word little snyder Word VBA 4 11-23-2013 05:19 AM
Creating alphanumeric incremental serial numbers Sorting Alphanumeric & Numeric values slovenc0417 Excel 2 06-07-2013 07:58 PM
Creating alphanumeric incremental serial numbers Creating styles in Word - alphanumeric lists jmichellephd Word 8 03-25-2013 12:14 AM
Creating alphanumeric incremental serial numbers Extract Numbers from Alphanumeric String OTPM Excel 6 05-13-2011 12:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft