automatically insert town name after entering zip code

G

Guest

I have created a sheet in which I am entering addresses. I created a drop
down list for the seven zip codes I am working with. Is there a way to have
excel automaticall y enter the corresponding town in the adjacent cell after
I choose a zip code?
 
A

abcd

Well it depends:

if it's a fixed cell, you may put a formula in the next cell
( a match / indirect couple OR a lookup function)

But you want this even with new lines, you'll need a vba code to
auto-add the new next-cell too:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then ' I suppose you enter zip in the column 3
Dim i&
On Error Resume Next
Application.EnableEvents = False
i = 0
' below I suppose all the known ZIP code are in the column A
' if unknown, match gives an error
' so i=0 because of "on error resume next"
i = Application.WorksheetFunction.Match(Target.Value, Range("A:A"), 1)
' below I suppose the associated Known City are in the B column
(column=2)
' and i suppose the city name must be on the right of the entered zip
code
If i > 0 Then: Target.Offset(0, 1).Value = Cells(i, 2)
Application.EnableEvents = True

End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top