How can i tie a word to a number

E

eqcitizen

How can i possibly tie a word to a number so that any time that word is
entered the number tied to it becomes the cell value.
 
G

Gord Dibben

You could have a helper cell with a formula.

=LOOKUP(A1,{"cat","dog","goat","horse","lion","ocelot";8,9,3,7,6,4})

Or to change the cell value that you typed into.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A1:A10")
If Intersect(Target, r) Is Nothing Then
Exit Sub
End If
vals = Array("Cat", "Dog", "Goat", "Horse", "Lion", "Ocelot")
nums = Array(8, 9, 6, 3, 7, 4)
For Each rr In r
inum = 0
For i = LBound(vals) To UBound(vals)
If rr.Value = vals(i) Then
inum = nums(i)
End If
Next
If inum > 0 Then
rr.Value = inum
End If
Next
End Sub


Gord Dibben MS Excel MVP
 

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