Originally Posted by
ValerieT
... How can I "translate" the string "ABCD" read from the cell, into the constant value = 5 ? in order to end up with something like that ...
Hi
An easy way is to define a function that will work kind of as an enum whose constants you can call by name, or kind of a static hash table.
Ex.:
Public Function MyConstants(sConst As String) As Variant
Select Case sConst
Case "ABCD": MyConstants = 3
Case "EFGH": MyConstants = 5
Case "IJKL": MyConstants = "Hi there!"
Case Else: MyConstants = "#N/A"
End Select
End Function
Now you can, for ex., use:
Sheets("Total Population").Cells(Ou, MyConstants(My_Position)) = My_Total
Remarks:
This is just an answer to your vba syntax question, "how can I ...."
There are other solutions, like Aflatoon posted, some dynamic, for ex. using a dictionary or a collection.
Maybe you can redesign the solution and not need this at all. Aflatoon's suggestion of using Names seems a good way to go.