• 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.

Pad Text entry based on Combo Box selection

Hi,
Yeah, I know the title doesn't really make sense, but I couldn't find a better way to explain what I want to do.
I have a Combo box and a Text box on a UserForm. What I need to do is to have a user select a String value from the Combo box, and have it entered into the Text box, BUT not all of the text, just 3 letters from the text.
Eg. The Combo box has names of cities like Agra, Allahabad, Meerut, Mahoba etc. and I need the Text box to show only AGR for Agra, ALD for Allahabad, MEE for Meerut, MAH for Mahoba etc. In other words, I want to show only abbreviations of the cities instead of their full names.

Can anyone share how to do this ? Greatly appreciate any answers. I am using Excel 2013 on Windows 7.
Regards,
Maneesh
 
Hi Hui,
Thanks for responding, but this is not working for me. I can't figure out why ?
Here's what I'm doing:

Code:
Private Sub Arec4_Change()
            Arec6.Text = UCase(Left(Arec4.Text, 3))
            UpdatePID
           End Sub

The name of the Combo Box is Arec4 and the Text Box is named Arec6.
What am I doing wrong here ???
~~ Maneesh
 
Last edited:
Hi Hui,
I'v checked to see why the code you suggest is not working. Its because I'm using the UpdatePID function just after your code.
This is what I need to do:
I have a few Combo boxes on a userform. 3 components are used to make up an ID of an agent that the user has to select which then goes into a Text box. The 1st Combo box is a Region combo box[named 'Arec1'] having 3 values (E,W and C) ('E' for East, 'W' for West and 'C' for Central), the 2nd Combo box is the Zone combo box[named 'Arec2'] which has numbers from 1 to 10 for 10 zones, the 3rd Combo box is a City Combo box[named Arec3] which has names of cities. The user has to use all the 3 Combo boxes to make up the full components of the ID. For Example, selecting 'E' from 1st Combo box, '7' from 2nd Combo box and 'Agra' from 3rd Combo box would make up : E7AGR as the Agent's ID. Then I am using the following code to gather all the components from the 3 Combo boxes into a Text box (named Arec6).
Here's the code I'm using:
Code:
Private Sub Arec1_Change()
UpdatePID
End Sub

Private Sub Arec2_Change()
UpdatePID
End Sub

Private Sub Arec4_Change()
Arec6.Value = UCase(Left(Me.Arec4.Value, 3))
UpdatePID
End Sub

Private Sub UpdatePID()
    Me.Arec6 = Me.Arec1 & Me.Arec2 & Me.Arec4
End Sub

Calling the UpdatePID function immediately after your suggested code above in the Arec4_Change() Combo box event is not "holding on" to the whatever is being selected from the Arec1 and Arec2 Combo boxes. The Text box becomes empty on calling the UpdatePID function.

How should I fix the above issue?
~ Regards,
Maneesh
 
Hi, Maneesh Massey!
Tried this yet?
Code:
Option Explicit

Private Sub Arec1_Change()
    UpdatePID
End Sub

Private Sub Arec2_Change()
    UpdatePID
End Sub

Private Sub Arec4_Change()
    UpdatePID
End Sub

Private Sub UpdatePID()
    Me.Arec6 = Me.Arec1 & Me.Arec2 & UCase(Left(Me.Arec4, 3))
End Sub
Regards!
 
Hi, Maneesh Massey!
Tried this yet?
Code:
Option Explicit

Private Sub Arec1_Change()
    UpdatePID
End Sub

Private Sub Arec2_Change()
    UpdatePID
End Sub

Private Sub Arec4_Change()
    UpdatePID
End Sub

Private Sub UpdatePID()
    Me.Arec6 = Me.Arec1 & Me.Arec2 & UCase(Left(Me.Arec4, 3))
End Sub
Regards!
Thanks so much !!! Works like a charm !!!
 
Hi, Maneesh Massey!
Glad you solved it, I didn't anything but putting your code in the simplest way. Welcome whenever needed or wanted.
Regards!
 
Hi, Maneesh Massey!
Tried this yet?
Code:
Option Explicit

Private Sub Arec1_Change()
    UpdatePID
End Sub

Private Sub Arec2_Change()
    UpdatePID
End Sub

Private Sub Arec4_Change()
    UpdatePID
End Sub

Private Sub UpdatePID()
    Me.Arec6 = Me.Arec1 & Me.Arec2 & UCase(Left(Me.Arec4, 3))
End Sub
Regards!

Hi,

I would like to have a text box on the UserForm show the first name, last name initials, convert that into upper case from an entry made in another text box on the same UserForm on the Textbox_Exit event of the second textbox.

Eg.
Code:
Private Sub Arec7_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Some Code here to make this work...
UpDatePID
End Sub

Private Sub UpdatePID()
    Me.Arec6 = Me.Arec1 & Me.Arec2 & UCase(Left(Me.Arec4, 3))
End Sub

I am using the following code, but its not working.

Code:
Left(Me.Arec7.Value, 1) & Mid$(Me.Arec7.Value, instr(Me.Arec7.Value, " ") + 1, 1)

You helped on this sometime back when I wanted to extract a string in this same post. Please help me. Appreciate all help. Thanks.
Regards,
Maneesh
 
Hi, Maneesh Massey!
Specify which are the controls for 1st and last name and for the "another" text box.
Post all code involving those controls, or better indeed consider uploading a sample file (including manual examples of desired output if applicable), it'd be very useful for those who read this and might be able to help you.
Regards!
 
Hi, Maneesh Massey!
Specify which are the controls for 1st and last name and for the "another" text box.
Post all code involving those controls, or better indeed consider uploading a sample file (including manual examples of desired output if applicable), it'd be very useful for those who read this and might be able to help you.
Regards!


Hi,
Arec7 is the textbox in which the user enters his/her full name. And I need the textbox called Arec6 to show initials of first and last names in this textbox(Arec6).
UpDatePID is a Sub which updates the entries from all the textboxes and displays it on the userform.

Let me know if you have any other queries.
Many thanks.
Regards,
Maneesh
 
Hi, Maneesh Massey!

So:
a) User only types the full name in text box Arec7
b) Text box Arec6 is for showing the initials. BTW, how many 1st names and last names are allowed? There is John Smith, Armando Esteban Quito, Jean Pierre Celam Astique, ... i.e., 1&1, 2&1, 2&2. Elaborate on this.
c) What are text boxes Arec1/2/4 for?

Despite of this I think that you should:
1) Have 1 control for the 1st name, Garch1, manually inputted
2) Have 1 control for the last name, Garch2, manually inputted
3) Have 1 control for the full name, Garch3, updated in UpdateID
4) Have 1 control for the 1st name initials, Garch4, updated in UpdateID
5) Have 1 control for the 1st name initials, Garch5, updated in UpdateID

Everywhere you're asked to enter your name, the last method is used; in your requirements you're doing exactly the opposite. If I were you I'd evaluate again the whole stuff.

Regards!
 
Back
Top