Consulting

Results 1 to 4 of 4

Thread: Trim and LCase values in an array

  1. #1
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location

    Trim and LCase values in an array

    Hi Folks

    Trying to trim values in an array, however, I always run into a Runtime Error 13 (Types don't match)

    For example, I save a worksheet range in an array like so:

    Dim myArr as Variant : myArr = ws.Range("A1:A100")

    Then trying to trim:

    Dim i as variant
    For each i in myArr
    Trim(myArr(1,i)
    Next i

    By the way I'm using Option Base 1.

    Strangely, If I try to use Trim on a worksheet, I doesnt raise an error, but neither does it trim

    Any ideas?

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Runtime Error 13 (Types don't match)
    For Each (Item) in an array doesn't work.

    Dim i as long
    For i = LBound(MyArr) to Ubound(myArr)
       myArr(i) = lCase(Trim(myArr(i)))
    Next i
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    Thank you Sam, that does the trick DD

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Sub M_snb()
       sn = [index(trim(lower(A1:A100)),)]
    End Sub

Posting Permissions

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