Consulting

Results 1 to 18 of 18

Thread: How to retrieve the alphabets of a word

  1. #1

    How to retrieve the alphabets of a word

    Hi all,

    I want to retrieve the alphabets of a word.
    Ex: MY name is YOGESHWAR
    now is there any formula so that I could find out
    what is the first alphabet of YOGESHWAR ?
    what is the second alphabet of YOGESHWAR ?
    what is the third alphabet of YOGESHWAR ?
    what is the fourth alphabet of YOGESHWAR and so on..........

    Can somebody help me out on this task?

    Yogeshwar

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    yogeshwar, by alphabet do you mean each letter in your name or the contents of an Excel cell?

  3. #3
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    [VBA]
    Option Explicit

    Sub GetLetters()

    Dim N As Long, MyString As String

    MyString = "yogeshwarv"

    For N = 1 To Len(MyString)
    Range("A" & N) = Right(Left(MyString, N), 1)
    Next
    End Sub
    [/VBA]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Why not
    [VBA]
    Range("A" & N) = Mid(MyString, N, 1)
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =MID(A1,1,1)
    and

    =MID(A1,2,1)
    where A1 is the name

  6. #6
    VBAX Expert Shazam's Avatar
    Joined
    Sep 2005
    Posts
    530
    Location
    If the cell always have 9 characters then try..

    First letter of the alphabet

    =CHAR(SMALL(CODE(MID(A1,{1;2;3;4;5;6;7;8;9},1)),1))

    Second letter of the alphabet

    =CHAR(SMALL(CODE(MID(A1,{1;2;3;4;5;6;7;8;9},1)),2))

    Third letter of the alphabet

    =CHAR(SMALL(CODE(MID(A1,{1;2;3;4;5;6;7;8;9},1)),3))
    SHAZAM!

  7. #7
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    And - for a little fun [vba]Sub GetLettersBackwards()
    Dim N As Long, MyString As String
    MyString = "YOGESHWAR"
    For N = 1 To Len(MyString)
    Range("A" & N) = Left(Right(MyString, N), 1)
    Next
    End Sub[/vba]
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  8. #8
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    835
    Location
    Well as long as were having fun, how about all the 4 letter word possibilities that could be derived from "YOGESHWAR"? Dave
    ps. some of the word are pretty lame

    edit:forgot option base
    [VBA]
    Option Explicit
    Option Base 1
    Sub RandWrdFrmName()
    Dim AR() As Variant, MyString As String, N As Integer
    Dim TotChars As Integer, Cnt As Integer, WdString As String
    MyString = "YOGESHWAR"
    ReDim AR(Len(MyString))
    For N = 1 To Len(MyString)
    AR(N) = Mid(MyString, N, 1)
    Next
    Randomize
    'Totchars = Int((Len(MyString) * Rnd) + 1)'rndommize word length
    TotChars = 4 ' make 4 letter words
    Do
    WdString = vbNullString
    For Cnt = 1 To TotChars
    WdString = WdString + AR(Int((Len(MyString)) * Rnd) + 1)
    Next Cnt
    Loop Until Application.CheckSpelling(WdString)
    MsgBox "Your random " & TotChars & " character(s) word is: " & WdString
    End Sub
    [/VBA]
    Last edited by Dave; 12-11-2006 at 10:48 AM. Reason: no option base 1

  9. #9
    VBAX Mentor CBrine's Avatar
    Joined
    Jun 2004
    Location
    Toronto, Canada
    Posts
    387
    Location
    Well, in the name of fun how about random letter colors?
    [vba]
    Sub RandomColor()
    Dim cell As Range, reverse As String
    Randomize
    For Count = 1 To ActiveCell.Characters.Count
    ActiveCell.Characters(Count, 1).Font.Color = RGB(Int((255 * Rnd) + 1), Int((255 * Rnd) + 1), Int((255 * Rnd) + 1))
    Next Count
    End Sub

    [/vba]
    The most difficult errors to resolve are the one's you know you didn't make.


  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Get a grip children, the bloke is looking for assistance, not your amusement.

  11. #11
    VBAX Mentor CBrine's Avatar
    Joined
    Jun 2004
    Location
    Toronto, Canada
    Posts
    387
    Location
    xld,
    John solved this issue in his first post, now we are just having a little fun. RELAX, life's to long to be serious all the time.

    Here's some revised code that randomize's the font color, but also display's each character from the cell. So fun, and serious all at the same time.


    Cal

    [vba]
    Sub ShowCharacter()
    Dim cell As Range, reverse As String
    Randomize
    For Count = 1 To ActiveCell.Characters.Count

    MsgBox ActiveCell.Characters(Count, 1).text

    'REMOVE THIS TO STOP RANDOM COLORING.
    ActiveCell.Characters(Count, 1).Font.Color = RGB(Int((255 * Rnd) + 1), Int((255 * Rnd) + 1), Int((255 * Rnd) + 1))
    Next Count
    End sub
    [/vba]
    The most difficult errors to resolve are the one's you know you didn't make.


  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    There are off-topic forums if you want a little fun. Personally I object to you over-loading a serious question with such drivel, trying to show us what a clever coder you are. It means that I waste my time reading it thinking that there might be some serious contribution, and the OP might well be turned off the forum thinking that he is not taken seriously.
    Last edited by Bob Phillips; 12-11-2006 at 06:28 PM.

  13. #13
    Administrator
    2nd VP-Knowledge Base VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Bob has a point...I wouldn't want to offend someone if they thought we weren't taking his/her question seriously.


    ...Let's see what the OP says. If it were me, I would be excited to see what VBA could do and it might give me ideas for other coding tasks...but that's me, not yogeshwarv.




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  14. #14
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by yogeshwarv
    Hi all,

    I want to retrieve the alphabets of a word.
    Ex: MY name is YOGESHWAR
    now is there any formula so that I could find out
    what is the first alphabet of YOGESHWAR ?
    what is the second alphabet of YOGESHWAR ?
    what is the third alphabet of YOGESHWAR ?
    what is the fourth alphabet of YOGESHWAR and so on..........

    Can somebody help me out on this task?

    Yogeshwar
    It also depends on exactly what Yogeshwar means by this. I took alphabets of a word' to mean 'letters of a word' and my original post gives the 1st, 2nd, 3rd, ..., etc letters counting from the left (and = Right(Left(MyString, N), 1) could be easily adapted to a worksheet formula if desired).

    But what is really meant by 1st, 2nd, 3rd, ..., and so on? Is it 1st, 2nd, 3rd, ..., etc from the left, or 1st, 2nd, 3rd, ..., etc from the right? My second post redresses this by counting letters from the right (if that really was an issue, and = Left(Right(MyString, N), 1) can also be adapted)

    However, Yogeshwar could also mean first retrieving, and then sorting the letters in alphabetical order (which could be done with a simple sort of either of those results)...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  15. #15
    VBAX Mentor asingh's Avatar
    Joined
    Jul 2005
    Posts
    307
    Location
    Hi,

    Find attached a file, that will do it using..formula's only.


    regards,

    asingh

  16. #16
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Asingh,
    Just a thought, but if you started your formula in Row 1 or Column 1 you could use Row() or Column() which avoids the need for the StringCounter
    eg.
    =IF(LEN($B$1) = 0,"",MID($B$1,(LEN($B$1)-LEN($B$1)+ROW()),1))
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  17. #17
    HI,

    Sorry for being late on this forum.
    I believe XLD is correct this is exactly what I needed.
    I knew there is formula in excel but I was not able to recall that.
    I am new to VBA and I am trying to learn the same.

    Thanks to every body who replied in this forum.

    Basically, What i wanted to learn to very clear.
    I wanted to know the 1st, 2nd, 3rd, 4th letter of alphabet in a word.... and so on..

    Thanks for great help

  18. #18
    VBAX Contributor
    Joined
    Jul 2004
    Location
    Gurgaon, India
    Posts
    148
    Location
    Hi,

    In B1 and copied across,

    =IF(COLUMNS($B$1:B$1)<=LEN($A$1),MID($A$1,COLUMNS($B$1:B$1),1),"")

    HTH

Posting Permissions

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