• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change names in textbox in userform

Hello,
In a userform 2 labels are populated with names coming from a sheet called members, this sheet is populated from governement software for reading ID cards and cannot be changed
The first label exist out of 1 or more names, the second label exists of one or 2 names
Example
First label: Jack Bert and second label: Vanpeel DeCock
Note: First label can have more names like: Jack Bert Julia
Second label can only have 2
Now my question is is it possible to have a TextBox populated like this:
Jack (V-D) What means the first name from label 1 (the others can be ignored) And the first letter of the name(s) in label 2
Thanks for any help
 
Essentially this is a string manipulation type question. You'll want to set the initial strings in this example based on the textbox values, but this should give you the overall idea.

Code:
Sub ExampleStrings()
    Dim strOne As String
    Dim strTwo As String
    Dim strConcat As String
    Dim strFinal As String
    Dim xData As Variant
    Dim i As Integer
   
    'You would normally get these from the label value. For example, I'll assign them direct
    strOne = "Jack Bert"
    strTwo = "Vanpeel DeCock"
   
    'Split the first, grab only first word
    xData = Split(strOne, " ")
    strFinal = xData(0)
   
    'Split other string, concatenate parts
    xData = Split(strTwo, " ")
   
    For i = 0 To UBound(xData)
        strConcat = strConcat & "-" & Left(xData(i), 1)
    Next i
   
    strFinal = strFinal & " " & Mid(strConcat, 2)
   
   
    'Do something with final output
    MsgBox strFinal

End Sub
 
Hello Luke,
Thank you for your reply, but I can't get it to work.
Can you have a look at the included file please
 

Attachments

  • test.xlsb
    99.3 KB · Views: 3
Hi Luke,
Thank you for your fast and excellent help, In the example file it works fine I will test it tomorrow in the real file and I'll come back to you
Have a nice evening
 
Back
Top