Drop Down List HELP

coach_veto

New Member
Joined
Jan 26, 2016
Messages
15
Hi,
My problem sounds very simple but I cannot figure out how to fix it with regular formulas or VBA code.

Example: Let's say I have a drop down list that applies to cells A1:A50. My choices within the list are "United States," "United Kingdom," and "Ireland." Here's my issue: When I pick 1 of my 3 options from the list, I want "US," "UK," or "IR" to appear. So when I click on "United States" from my list in cell A1, I would want "US" to populate instead. If I picked "Ireland" instead though, I would want "IR" to appear and so on...

How can this be done with either formulas or VBA code?

Thanks guys
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Thought of using vlookup, but I cannot enter a formula in the cells that have the drop down list. If I could, I think it might also create a circular reference because the text I want ("US") depends on what is picked from the list in the active cell (United States/United Kingdom/Ireland).
 
Upvote 0
Right click on your sheetname, choose View Code, paste the below code:

Code:
Private Sub worksheet_change(ByVal target As Range)

If Not Intersect(target, Range("A1")) Is Nothing Then

Select Case Range("A1").Value

Case "United States"

   Range("A1").NumberFormat = ";;;""US"""

Case "United Kingdom"

   Range("A1").NumberFormat = ";;;""UK"""

Case "Ireland"

   Range("A1").NumberFormat = ";;;""IR"""


End Select

End If

End Sub
 
Upvote 0
Another option?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)


country = Target.Value


Select Case country
   Case "United States"
      Target.Value = "US"
   Case "United Kingdom"
      Target.Value = "UK"
   Case "Ireland"
      Target.Value = "IR"
 End Select


End Sub
 
Upvote 0
This code only applies to cell A1. It won't work for the other cells in column A. If I wanted to fix that, how would I change your code? For example, what if I wanted this to apply to cells A1:A50?
 
Upvote 0
@Caribeiro77 that code works for all the cells that have a list. Thank you! it answered my previous question regarding PATSYS answer
 
Upvote 0
Which one? Mine or PATSYS, cause i tried mine and it work everywhere...
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,604
Members
449,174
Latest member
ExcelfromGermany

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top