+ Reply to Thread
Results 1 to 10 of 10

Can I use TEXT function with Evaluate in VBA

  1. #1
    Registered User
    Join Date
    01-26-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    5

    Can I use TEXT function with Evaluate in VBA

    Hello

    I am trying to come up with code that will be used on a range of client numbers expressed as integers like 100 and 2020 and change them into six character text values expressed like 000100 and 002020.

    I am trying to alter this trim code that works great to fit my needs:

    Please Login or Register  to view this content.
    I thought I could alter the above code to this but it doesn't do anything:

    Please Login or Register  to view this content.
    I would be forever grateful if you have any ideas. I would prefer not to incorporate a loop if I don't have to because some of my worksheets have a hundred thousand plus rows and that will take forever to work through them all. Evaluate seems to handle that many rows easily with the trim function above.

    Thank you so much.
    T
    Last edited by faulconert; 01-27-2018 at 05:23 PM. Reason: Clarify my question

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Can I use TEXT function with Evaluate in VBA

    VBA equivalent of =TEXT(A1,"000000") :
    Please Login or Register  to view this content.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    01-26-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    5

    Re: Can I use TEXT function with Evaluate in VBA

    Kev_, thank you for the quick reply. When I swap out the "TEXT" for "Format" in my code I get a #VALUE! error.

  4. #4
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Can I use TEXT function with Evaluate in VBA

    Why are you using evaluate instead of range.formula?

    Do you want the formula to be placed in the cell or just the value placed in the cell?

    If your code places the formula into the cell, FORMAT() wont work as its a VBA function, not a worksheet function.

    Is the formula already in the cells and you want to just add this formatting to them? Does putting TEXT in as you have it work if you manually add it to a formula on the sheet (not using the macro)?
    Last edited by Zer0Cool; 01-26-2018 at 05:42 PM.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  5. #5
    Registered User
    Join Date
    01-26-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    5

    Re: Can I use TEXT function with Evaluate in VBA

    Zer0Cool, I appreciate you replying.

    I am not trying to trim anything that was just code that I tried to adjust to fit my needs. I actually don't want the formulas I want to change the values in the cell. I am trying to come up with code that will be used on a range of client numbers expressed as integers like 100 and 2020 and change them into six character text values expressed like 000100 and 002020.

  6. #6
    Forum Contributor
    Join Date
    01-03-2018
    Location
    Fukuoka, Japan
    MS-Off Ver
    Excel 2013
    Posts
    123

    Re: Can I use TEXT function with Evaluate in VBA

    Why don't you use custom number format?

    How to display leading zeros with Excel custom format

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

    Re: Can I use TEXT function with Evaluate in VBA

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

  8. #8
    Registered User
    Join Date
    01-26-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    5

    Re: Can I use TEXT function with Evaluate in VBA

    Thank you, jindon. That works for me!

    Thanks to everyone that replied.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Can I use TEXT function with Evaluate in VBA

    You might also simply set the numberformat of the range to @ before using your original Evaluate statement with TEXT.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  10. #10
    Registered User
    Join Date
    01-26-2018
    Location
    Chicago
    MS-Off Ver
    2010
    Posts
    5

    Re: Can I use TEXT function with Evaluate in VBA

    ahhhh... Good thinking xlnitwit! Thank you. I think this post is solved.

+ 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. VBA Evaluate function
    By asheshrocky in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-07-2011, 03:36 AM
  2. Evaluate function in VBA
    By keith101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2010, 06:37 PM
  3. [SOLVED] EVALUATE Function
    By Frank H. in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 09-09-2009, 04:02 PM
  4. Evaluate function
    By sachinkatre in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2009, 04:49 PM
  5. Function Evaluate
    By raty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2008, 05:58 AM
  6. [SOLVED] Please evaluate my new function
    By Caezar in forum Excel General
    Replies: 3
    Last Post: 08-16-2006, 12:25 PM
  7. Evaluate text string as a function
    By benb in forum Excel General
    Replies: 3
    Last Post: 07-19-2006, 09:45 AM
  8. evaluate a function
    By Ali Baba in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-03-2005, 02:05 AM

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