+ Reply to Thread
Results 1 to 11 of 11

Function to determine if a string contains multibyte characters or not

  1. #1
    Registered User
    Join Date
    02-10-2013
    Location
    Frankfurt, Germany
    MS-Off Ver
    Excel 2003
    Posts
    57

    Function to determine if a string contains multibyte characters or not

    Hi,

    I'm trying to write a really simple function which will return either TRUE or FALSE depending on whether a string contains multibyte characters or not. The reason I need to do this is to create another string handling function, however, it needs to know if it's handling a western or Japanese string first. So, it would work something like this:

    MultibyteChecker("We ate bacon and bread") = FALSE

    MultibyteChecker("ベーコンとパンを食べた") = TRUE

    Thanks a lot for reading!

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

    Re: Function to determine if a string contains multibyte characters or not

    =LEN(A1)<>LENB(A1)
    Should return True/False

  3. #3
    Registered User
    Join Date
    02-10-2013
    Location
    Frankfurt, Germany
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Function to determine if a string contains multibyte characters or not

    Hi,

    Thanks a lot for the reply! Based on that, I wrote something like this:

    Please Login or Register  to view this content.
    However, it's returning true for both strings right now. Is there something that I've missed? Do you know if there's any other way to distinguish between strings containing Japanese text or not?

    Thanks!

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Function to determine if a string contains multibyte characters or not

    Check the below link

    https://www.reddit.com/r/excel/comme...n_a_text_cell/

    Formula solution given in the above link

    =IF(A1="","",IF(ISERROR(SUMPRODUCT(SEARCH(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),"0123456789abcdefghijklmnopqrstuvwxyz.;,"))),"NON-ENGLISH","ENGLISH"))

    Converting the above formula to VBA is not a big deal.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

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

    Re: Function to determine if a string contains multibyte characters or not

    LenB in vba is different from worksheet function.

    A bit tricky...
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-10-2013
    Location
    Frankfurt, Germany
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Function to determine if a string contains multibyte characters or not

    @Jindon: I tried that code, but I'm now getting "FALSE" for both strings (and for one containing both double and single byte characters.

    @SixthSense: Thanks a lot, I also tried this formula, but similarly, this is returning "NON-ENGLISH" for both strings as well. Also, for my application, I think byte-counting will probably work better, but thanks so much anyway.

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

    Re: Function to determine if a string contains multibyte characters or not

    See...................
    Attached Files Attached Files

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Function to determine if a string contains multibyte characters or not

    You may try simple loop:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  9. #9
    Registered User
    Join Date
    02-10-2013
    Location
    Frankfurt, Germany
    MS-Off Ver
    Excel 2003
    Posts
    57

    Re: Function to determine if a string contains multibyte characters or not

    @Izandol: Thanks so much, that completely solves my issue. (I'll be honest, I'm not familiar with variables like "Byte" or functions like "LBound", so I would never have thought of that).

    @Jindon: Thanks again for the illustrative sheet. When I opened it, it was showing the correct output, however, when I recalculated the formulas, it was back to returning everything as FALSE again. So I guess this is something that works fine at your end, but not at mine for some reason! Maybe it's because of this, a bit of info that I found on the MS Office website:

    LENB counts 2 bytes per character only when a DBCS language is set as the default language. Otherwise LENB behaves the same as LEN, counting 1 byte per character.

    Thanks to everyone who helped me out with this!

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

    Re: Function to determine if a string contains multibyte characters or not

    Ah I see, thanks for the link.

  11. #11
    Registered User
    Join Date
    07-24-2017
    Location
    London
    MS-Off Ver
    16
    Posts
    1

    Re: Function to determine if a string contains multibyte characters or not

    This formula says it is invalid in EXCEL 2016! what is the problem?

    =IF(A1="","",IF(ISERROR(SUMPRODUCT(SEARCH(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),"0123456789abcdefghijklmnopqrstuvwxyz.;,"))),"NON-ENGLISH","ENGLISH"))

+ 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. [SOLVED] VBA, remove all characters within a string, except numerical characters and full stops
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2015, 09:24 PM
  2. [SOLVED] Function for String between 2 characters?
    By devpp in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-30-2014, 08:42 AM
  3. [SOLVED] COUNTIF Function for String of more than 255 Characters
    By akbarmajor in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-17-2014, 10:34 AM
  4. [SOLVED] Function to flag non-alphanumeric characters in a text string
    By Sophie.Durrant in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-02-2013, 10:56 AM
  5. [SOLVED] Extract left characters from string with exception of 2 right characters
    By sweetkel23 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-16-2012, 10:45 PM
  6. [SOLVED] Function to trim first 10 characters off a string
    By theletterh in forum Excel General
    Replies: 5
    Last Post: 07-12-2012, 11:43 AM
  7. UTF-16 Multibyte characters
    By John Bates in forum Excel General
    Replies: 0
    Last Post: 05-13-2010, 11:20 AM

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