Consulting

Results 1 to 4 of 4

Thread: Solved: Join an array and join a Range

  1. #1
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location

    Solved: Join an array and join a Range

    I'm having an issue with these codes:

    [VBA]Sub Test1()
    '***
    'Values of cells A1 = "Hi" and B1 = "Lo"
    '***

    Debug.Print Join(Range("A1:B1"), ", ") 'I want 'Hi, Lo' as output.
    End Sub
    [/VBA]

    and this:

    [VBA]Sub Test2()
    '***
    'Values of cells A1 = "Hi" and B1 = "Lo"
    '***

    Dim var 'What type is this variable?

    Set var = Range("A1:B1")

    Debug.Print Join(var, ", ") 'I want 'Hi, Lo' as output.
    End Sub
    [/VBA]

    How do I make them work?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim ary

    ary = Range("A1:B1")
    Debug.Print Join(Application.Transpose(Application.Transpose(ary)), ", ")
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    This seems to work:
    [VBA]Debug.Print Join(Application.Index(Range("A1:B1").Value, 0), ", ")[/VBA]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Tutor Benzadeus's Avatar
    Joined
    Dec 2008
    Location
    Belo Horizonte, Brazil
    Posts
    271
    Location
    Thank you very much.

Posting Permissions

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