Consulting

Results 1 to 10 of 10

Thread: Solved: Changing Names to Numbers

  1. #1
    VBAX Regular
    Joined
    Mar 2008
    Posts
    90
    Location

    Post Solved: Changing Names to Numbers

    Hy guys,


    First of all sorry for my poor english language :|


    I have a column with people names, and I want to change this names in numbers.

    for example :

    I have this column:

    albert
    mario
    maria
    albert
    andrew
    john
    albert
    maria
    mario
    john
    andrew

    now i want to transform this names in numbers

    albert=210
    mario=211
    maria=212
    andrew=213
    john=214


    my new column must look like this:

    210
    211
    212
    210
    213
    214
    210
    212
    211
    214
    213

    Thanks!!

  2. #2
    Check out the attachment...

  3. #3

    Thumbs up Use vlookup function

    Check out the attachment...

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Assuming you don't have the lookup values in a worksheet

    [vba]

    Public Sub ProcessData()
    Const TEST_COLUMN As String = "A" '<=== change to suit
    Dim i As Long
    Dim LastRow As Long
    With Application

    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    For i = 1 To LastRow

    With .Cells(i, TEST_COLUMN)

    Select Case LCase(.Value)

    Case "albert": .Value = 210
    Case "mario": .Value = 211
    Case "maria": .Value = 212
    Case "andrew": .Value = 213
    Case "john": .Value = 214
    End Select
    End With
    Next i

    End With

    With Application

    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Mar 2008
    Posts
    90
    Location

    ..

    thanks xld , this code works , but I still have a problem , in my database I have at least 56 diferent operators names.

    << Case
    "albert": .Value = 210
    Case
    "mario": .Value = 211
    Case "maria": .Value = 212
    Case
    "andrew": .Value = 213
    Case
    "john": .Value = 214 " >>

    If i must change in this code albert, john etc... with the operators names .. ...I still have a lot of work to do. I'll put an attachement with a sample of my DB.

    Thanks again!




  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You have to do the work somewhere. Either update the code, or create a list in a worksheet that can be checked against.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Quote Originally Posted by neditheg

    If i must change in this code albert, john etc... with the operators names .. ...I still have a lot of work to do.


    HI neditheg,

    Perhaps you wrote this with a different concept in mind, but the reality is as Bob has suggested. You do indeed have some work to do, but its a whole lot less than if you didn't have the code as he has provided.


    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  8. #8
    VBAX Regular
    Joined
    Mar 2008
    Posts
    90
    Location
    I know that and i've made that list to update the code.

    Thanks!!

  9. #9
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location
    maybe you can use the replace function?
    it will do the job, and with less typing than makeing a macro for it.

  10. #10
    VBAX Regular
    Joined
    Mar 2008
    Posts
    90
    Location
    did u see my db? i've made the macro thanks to xld, but i'll try ur solution too if u give me the right function format

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •