+ Reply to Thread
Results 1 to 13 of 13

How to convert any types format into Text with 5 digits in selection?

  1. #1
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    How to convert any types format into Text with 5 digits in selection?

    How to convert any types format into Text with 5 digits in selection?

    For instance, the content I select is "234", and I want it to convert to "00234". Just like the function "TEXT" in excel. How can I realize it promptly in VBA?

    Thanks!!!

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to convert any types format into Text with 5 digits in selection?

    VBA's Format function works the same as TEXT.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: How to convert any types format into Text with 5 digits in selection?

    but I try
    Please Login or Register  to view this content.
    it doesn't work.

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

    Re: How to convert any types format into Text with 5 digits in selection?

    Perhaps
    Please Login or Register  to view this content.
    Last edited by jindon; 08-19-2014 at 08:52 PM.

  5. #5
    Registered User
    Join Date
    07-17-2014
    Location
    Turkey
    MS-Off Ver
    2003
    Posts
    85

    Re: How to convert any types format into Text with 5 digits in selection?

    http://i.hizliresim.com/X2pkBD.jpg

    TextBox2 = Format(TextBox1, "00000")
    Attached Files Attached Files

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

    Re: How to convert any types format into Text with 5 digits in selection?

    deleted......

  7. #7
    Registered User
    Join Date
    07-17-2014
    Location
    Turkey
    MS-Off Ver
    2003
    Posts
    85

    Re: How to convert any types format into Text with 5 digits in selection?

    Perhaps

    Range("A1").Select
    Selection.NumberFormat = "00000"

  8. #8
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: How to convert any types format into Text with 5 digits in selection?

    @jindon what has happened??

  9. #9
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: How to convert any types format into Text with 5 digits in selection?

    Thank you guys!
    @jindon your code is what I exactly want! But how does it work? Why use "@" and why put a $ after Fomat??

    However, another problem shows up, it doesn't work when I choose a range.
    Please Login or Register  to view this content.
    Last edited by qzqzjcjp; 08-19-2014 at 09:23 PM.

  10. #10
    Registered User
    Join Date
    07-17-2014
    Location
    Turkey
    MS-Off Ver
    2003
    Posts
    85

    Re: How to convert any types format into Text with 5 digits in selection?

    Hello
    selection.JPG

    Select worksheet-> selection change event and write the code, there

    With Selection
    .NumberFormat = "@"
    .Value = Format$(Selection, "00000")
    End With
    Regards,


  11. #11
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: How to convert any types format into Text with 5 digits in selection?

    It still doesn't work. The error is always: Run-time error '13' Type mismatch. I modified the code a little bit and it works!!!
    Please Login or Register  to view this content.
    But another problem comes up, If I select the whole column or whole cells, it costs too much time to run.
    Last edited by qzqzjcjp; 08-19-2014 at 10:46 PM.

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

    Re: How to convert any types format into Text with 5 digits in selection?

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-07-2014
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    95

    Re: How to convert any types format into Text with 5 digits in selection?

    Thanks!!! Everyone!!

+ 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. How to convert digits in number to text
    By gusarmirko in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-18-2012, 03:56 AM
  2. Convert Digits to Text
    By [email protected] in forum Excel General
    Replies: 5
    Last Post: 03-22-2012, 08:22 AM
  3. I would like to convert digits (eg. 16) to text SIXTEEN in Excel
    By Naveen G. in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-10-2006, 03:29 AM
  4. Digits in text cannot format as Numbers ?
    By st24961 in forum Excel General
    Replies: 3
    Last Post: 05-31-2005, 01:45 AM
  5. [SOLVED] How can I convert digits to alpha text?
    By Richard Selzer in forum Excel General
    Replies: 1
    Last Post: 02-08-2005, 03: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