Results 1 to 5 of 5

Thread: Using TRIM with Evaluate Isn't Working

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    71

    Using TRIM with Evaluate Isn't Working

    Hi,

    I'm trying to use the following code to remove any leading or trailing spaces from values
    in column "C" of my worksheet:

    Code:
                  With Range(Cells(3, "C"), Cells(Rows.Count, "C").End(xlUp)
                       .Value = Evaluate(Trim(" & .Address & "))
                  End With
    Starting with initial values in column "C" of: J9768A, JC028A#A1X, JC085A, etc.,
    after running the above mentioned code, I get "#VALUE!" in all of the cells in column "C".
    Additionally, I tried to substitute ".Value" for ".Address" but get the same result.
    Any ideas why I'm getting the "#VALUE!" result?

    Thank You for any help provided.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Using TRIM with Evaluate Isn't Working

    Thread Moved to Office Development Forum from Visual Basic 6 Forum
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Using TRIM with Evaluate Isn't Working

    this does not make sense, you are effectively trying to evaluate the address of each cell

    Like
    Code:
                  With Range(Cells(3, "C"), Cells(Rows.Count, "C").End(xlUp)
                       .Value = Evaluate(Trim("$c$3"))
                  End With
    what are you actually trying to achieve?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    71

    Re: Using TRIM with Evaluate Isn't Working

    westconn1,
    Basically, trying to use the "Evaluate" function -
    that works on a range object - to execute the TRIM
    function on all values within the range specified.
    I realize this could also be done with a For-Next
    loop but I think the Evaluate would run faster and,
    I would like to learn how to use it.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Using TRIM with Evaluate Isn't Working

    Here is one piece of code which you will rarely see being used

    You can TRIM a range in one line i.e without looping.

    Code:
        Sub Sample()
            [C1:C1000] = [INDEX(TRIM(C1:C1000),)]
        End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

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



Click Here to Expand Forum to Full Width