Forum

Barcode ID split in...
 
Notifications
Clear all

Barcode ID split into few textbox in userform VBA

7 Posts
3 Users
0 Reactions
215 Views
(@mariyaulfa)
Posts: 6
Active Member
Topic starter
 

Hi all,

I am Mariya looking for assistance .

How to split barcode ID into few textbox as per attached after press command "ENTER" ? Note: Contains of ID are letter, number, space.

 

Form.PNG

 
Posted : 29/07/2019 11:06 am
Philip Treacy
(@philipt)
Posts: 1631
Member Admin
 

Hi Mariya,

Can you please supply your workbook and code otherwise anything we write will have to be rewritten to suit your environment.

Thx

Phil

 
Posted : 29/07/2019 7:52 pm
(@mariyaulfa)
Posts: 6
Active Member
Topic starter
 

Hi Phil,

Thanks for your reply. Attached as below.

You may click "CLICK ME" so that the userform will be pop-up. 

 
Posted : 30/07/2019 5:27 am
Philip Treacy
(@philipt)
Posts: 1631
Member Admin
 

Hi Mariya,

Please see attached.  Splitting up the code is pretty straightforward using VBA string functions

You could also read my Excel Forms posts to help you learn a bit more

Please note: the code in the workbook will only work if the code is always the same structure, that is, the same length and each of the substrings are the same length and in the same position.

Regards

Phil

 
Posted : 30/07/2019 11:38 pm
(@mariyaulfa)
Posts: 6
Active Member
Topic starter
 

Hi Phil,

The code works fine !

I really appreciate your help and read thru the website/forum post as you suggest.

Thanks, Phil 🙂

 
Posted : 01/08/2019 11:02 pm
Philip Treacy
(@philipt)
Posts: 1631
Member Admin
 

Glad to help 🙂

 
Posted : 02/08/2019 2:35 am
(@debaser)
Posts: 838
Member Moderator
 

FWIW, you could also use a couple of user-defined types, like this:

 

Private Type theBarcode
theCode As String * 30
End Type
Private Type BarcodeParts
BatchNumber As String * 7
space1 As String * 1
CodeNumber As String * 8
space2 As String * 1
Section As String * 1
space3 As String * 1
RequiredDate As String * 5
Prefix As String * 6
End Type

Private Sub CommandButton1_Click()

Dim BarCode As theBarcode
Dim theParts As BarcodeParts
BarCode.theCode = Range("B9").Value
LSet theParts = BarCode

tbScan.Value = BarCode.theCode
With theParts
BatchNum.Value = .BatchNumber
BatchMonth.Value = Left(.BatchNumber, 4)
Code.Value = .CodeNumber
Section.Value = .Section
RequiredDate.Value = .RequiredDate
Prefix.Value = .Prefix
End With

End Sub

 
Posted : 02/08/2019 7:54 am
Share: