+ Reply to Thread
Results 1 to 16 of 16

Clean the start of string only

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Clean the start of string only

    Hello everyone
    I have UDF of Mr. Karedog that cleans the end of specific string only
    Please Login or Register  to view this content.
    Now I need the vice versa .. to clean the start of the string only
    Would I reverse the loop ..? I am confused about that
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Clean the start of string only

    Hi,
    It seems that the presented function does check not every character near the end, but only every second one.

    Is it also the case in checking front?

    Anyway, may be at the beginning have a look on the following:
    Please Login or Register  to view this content.
    Last edited by Kaper; 02-11-2017 at 08:16 AM. Reason: sorry - typo in Mid :-(
    Best Regards,

    Kaper

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Clean the start of string only

    Thanks a lot for help but it doesn't seem to do the trick as I can't figure pairs of characters are to be removed.. I just need to clean any starting characters that are unusual such as chr(32) chr(160) .. hope this helps

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Clean the start of string only

    Have you tried the code? As it is now it shall do the work. If char(160) is also concerned, it can be added to case statement:
    Please Login or Register  to view this content.
    PS. Have you tried built-in function LTrim?

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Clean the start of string only

    Thanks a lot Mr. Kaper for great help
    I have tested LTrim and doesn't work for me
    As for the new UDF it is working but I need to make the number in this mid(param,2) variable (it is unknown for me) ...and that's the problem now
    Hope it is clear ..Let's try to stop when valid character (small or capital letters encountered ..)

    I have attached a file with one example ..
    Attached Files Attached Files
    Last edited by YasserKhalil; 02-11-2017 at 10:13 AM.

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Clean the start of string only

    Maybe :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Clean the start of string only

    That's Awesome & fascinating. Thanks a lot for great help Mr. Karedog
    Best and kind regards

  8. #8
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Clean the start of string only

    You are welcome.

    Regards

  9. #9
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Clean the start of string only

    Sir karedog what meaning param its array

  10. #10
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Clean the start of string only

    VBA can automatically convert a string to array of bytes.
    You can examine this example :
    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Clean the start of string only

    Is mean convert string to large number array (as byte)

  12. #12
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Clean the start of string only

    Yes, the array's size is twice the length of string.

  13. #13
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Clean the start of string only

    Ok thankyou sir karedog.

  14. #14
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Clean the start of string only

    sir karedog what mean Case 0 To 32, 127, 129, 141, 143, 144, 157 this is char$ for removing text and Mid$(param, (i + 2) \ 2) is mean if i = 0+2
    Please Login or Register  to view this content.

  15. #15
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Clean the start of string only

    Quote Originally Posted by daboho View Post
    what mean Case 0 To 32, 127, 129, 141, 143, 144, 157
    This thread is actually continuation of http://www.excelforum.com/excel-prog...t-the-end.html
    There is a link in the code that point to Microsoft's site that explain how the clean() function works. ( https://support.office.com/en-us/art...5-4b8ba987ba41 )
    In this site, you can see the number 0 To 32, 127, 129, 141, 143, 144, 157.


    Quote Originally Posted by daboho View Post
    this is char$ for removing text and Mid$(param, (i + 2) \ 2) is mean if i = 0+2
    Lets try this example :
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    The code loop from 0 (LBound(b)) to 21 (UBound(b))
    When i = 0 --> b(i) = 32 --> included for "Case 0 To 32, 127, 129, 141, 143, 144, 157" so proceed to next i
    When i = 2 --> b(i) = 32 --> included for "Case 0 To 32, 127, 129, 141, 143, 144, 157" so proceed to next i
    When i = 4 --> b(i) = 76 --> VBA found first non blank letter so terminate the For..Next loop

    To locate the position in the string (not the array), this formula is used :
    (i + 2) \ 2
    If you substitue i with 4, you will get (4 + 2) \ 2 = 6 \ 2 = 3 --> as you see the "L" is the third character of string " LLO WORLD"

  16. #16
    Forum Expert
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,513

    Re: Clean the start of string only

    Thankyou karedog

+ 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. Replies: 1
    Last Post: 08-07-2015, 04:01 PM
  2. Replies: 17
    Last Post: 01-25-2014, 06:31 AM
  3. Parse, Clean and Format Address Data from Text String
    By jerrydiaz in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-04-2013, 11:52 AM
  4. Creating a macro to clean up a text string
    By Steffen_DK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2012, 05:30 PM
  5. Text string clean up formula needed
    By ZimmJJ in forum Excel General
    Replies: 5
    Last Post: 07-01-2012, 09:16 PM
  6. [SOLVED] VBA Code to optimize and clean data- clean out numerical/ or symbol
    By tracylsr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-05-2012, 04:21 PM
  7. Clean up a string
    By quartz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2005, 12:06 PM

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