+ Reply to Thread
Results 1 to 33 of 33

How to access a char from a string? vba

  1. #1
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Lightbulb How to access a char from a string? vba

    how can i access a char in a string using vba code?? i tried using

    char = left((right(word), i),1)

    but it doesnt work

    thanks in advance!

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: How to access a char from a string? vba

    Suggest you post an example of what you are trying to do specifically. Your explanation does not provide enough detail and my crystal ball fell on the floor yesterday and shattered.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    ok for example i have something like 1,234,567,89 and i would like to access the 9 .. then the 8 then the comma then the 7 then the 6 then .. so on

  4. #4
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    store them one at a time in the value of char

    The main macro that i am making converts a string of numbers from text so that excel can interprate it as a number

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,882

    Re: How to access a char from a string? vba

    deleted as the response was not correct.

  6. #6
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    http://msdn.microsoft.com/en-us/libr.../ms233783.aspx

    i tried this as well but it doesn't seem to work in excel

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to access a char from a string? vba

    Is 1,234,567,89 the string you want to convert to a number?

    If it is then you could probably do it without going through each character one by one.

    What should the result be, 123456789 or 1234567.89?

    PS That link is for VB.NET.
    If posting code please use code tags, see here.

  8. #8
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    There are two possibilities 1.234.567,89 becomes 1234567.89 and 1,234,567.89 is also 1234567.89

    yes the 1,234,567,89 is the string i want converted to a number ..

    i am trying to do it for every number possible .. not only those .. so the number 15,65413551 should be 15.65413551

  9. #9
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    Please Login or Register  to view this content.

    there is the code i made so that it could work

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to access a char from a string? vba

    Don't you mean at least 3 possibilities?

    1.234.567,89
    1,234,567.89
    1,234,567,89

    1.234.567.89 perhaps?

  11. #11
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    yes but the program that those are being extracted from (SAP) don't have the other two .. and there are still some bugs in my code ..

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to access a char from a string? vba

    What 2 does SAP have?

    Your original post was about the string, 1,234,567,89.

    Then in a later post you post 3 more example strings, 1.234.567,89, 1,234,567.89 and 15,65413551.

    I'm pretty sure if you can clarify what you have then a solution that doesn't involve going through every character could be found.

    By the way, why are you getting this data in different number formats?

  13. #13
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    sap technically has 3 but one is recongnized by excel as a number right away witch is 1 234 567,89

    and the two that don't work are 1,234,567.89
    and 1.234.567,89

    sorry about the confusion ..


    norie .. sap is a pice of crap software .. is the best answer i can give you

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to access a char from a string? vba

    I've used SAP before and I can't recall it having different formats like that.

    Actually I think there was some (personal?) setting you could change to control numebr formats.

    Could you attach a workbook with some sample data that shows examples of all the different formats?

  15. #15
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    yes it is a personal setting, but many people use sap here and if one person extracts with a different setting then i have to change all the numbers from text to numbers especially when we get to the thousands.


    sap errors2.xlsx

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to access a char from a string? vba

    I'll have a look at the file, but a couple of quick questions.

    When you extract data how are you doing it?

    Also, does the extracted data have always have a mixture of date formats or does each extract always have the same date format?

  17. #17
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    We usually extract it with the extract to excel button .

    Its a good question I still don't know the exact answer to that since i am not the one who does the extracts.

  18. #18
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to access a char from a string? vba

    I was able to use Data>Text to columns... in your sample workbook to conver to numeric values.

    All I did was change round the decimal and thousand operators on the last step by going to Advanced...

    I don't know if that will work for all the formats you are encountering but it does with your sample data.

  19. #19
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to access a char from a string? vba

    Not sure but, is this how you wanted?

    If not, I need to see Before/After in the workbook.

    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: How to access a char from a string? vba

    to access the a character in a string you can use len() with for loop to get the position of each character in that string

    Please Login or Register  to view this content.

  21. #21
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    slx that didn't work in my case ... it doesn't give me the results that i want ..sap errors2.xlsx jindon look on sheet 2 for the desired answer

  22. #22
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    i made a mistake in the answer sheet ... but i believe i just realized something
    Attached Files Attached Files

  23. #23
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to access a char from a string? vba

    Maybe:
    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: How to access a char from a string? vba

    Here's it is going right to left.
    Please Login or Register  to view this content.
    To fix your problem u need to have clear rules.
    Starting with replace all "," with ".". Then count the ".", if there is only 1, then remove it If there more than 1, then use the first "." from the right. If there is none then leave it alone.

    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    nice try but no ciggar .. yudlugar i get an infinite loop and slx it just doesn't work it does nothing ..

  26. #26
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to access a char from a string? vba

    Have you actually tried my code?
    Attached Files Attached Files

  27. #27
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    jindon it works just that for the first one it should be 3000 ml and for the second it should be 6000 ml instead of 3 ml and 6 ml sorry..

  28. #28
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to access a char from a string? vba

    I see,

    This should do.
    Please Login or Register  to view this content.

  29. #29
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to access a char from a string? vba

    Or maybe simply
    Please Login or Register  to view this content.

  30. #30
    Forum Contributor
    Join Date
    04-24-2007
    Location
    NYC
    MS-Off Ver
    2k3/2k7/2010
    Posts
    270

    Re: How to access a char from a string? vba

    Roomie, it works, you have to be on sheet1 for it work since i didn't reference worksheets. The answer gets put in column "L" as demonstration.

  31. #31
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: How to access a char from a string? vba

    Please Login or Register  to view this content.
    ?

  32. #32
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: How to access a char from a string? vba

    jindon could we have the range change with the active cell function .. like change the values but only in the cell that is selected.. .... i don't know if i'm speaking Japanese

  33. #33
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: How to access a char from a string? vba

    Just change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Distributing string\char to each cells
    By janjan_376 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-04-2008, 03:13 PM
  2. Changing a single Char in a string to another ASCII char
    By goofy78270 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-15-2007, 09:45 AM
  3. sql string, +'/'+convert(char(3)..)
    By doristsr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2006, 03:40 AM
  4. [SOLVED] string/char CONTAINS function?
    By jim sturtz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-31-2006, 02:20 PM
  5. last char of a string
    By Buddy Lee in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-10-2005, 10:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1